Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / src / agent / service-adapter / protocol-binder / oma_ds_protocol_binder.c
1 /*
2  * oma-ds-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /**
19  *   @oma_ds_protocol_binder.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of callback function for Protocol Binder
22  */
23
24 #include <glib.h>
25
26 #include <sync_agent.h>
27
28 #include "service-adapter/protocol-binder/oma_ds_protocol_binder.h"
29 #include "service-adapter/sa_elements_internal.h"
30 #include "service-adapter/sa_command_internal.h"
31 #include "service-adapter/sa_devinf_internal.h"
32 #include "service-adapter/sa_command.h"
33 #include "service-adapter/sa_elements.h"
34 #include "service-adapter/sa_devinf.h"
35 #include "service-adapter/sa_define.h"
36
37 #ifndef OMADS_AGENT_LOG
38 #undef LOG_TAG
39 #define LOG_TAG "OMA_DS_BINDER"
40 #endif
41
42 static sync_agent_pb_error_e __append_location_to_wbxml_node(location_s * location, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node);
43
44 static sync_agent_pb_error_e __append_anchor_to_wbxml_node(anchor_s * anchor, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node);
45
46 static sync_agent_pb_error_e __append_devinf_contenttype_to_wbxml_node(devinf_content_type_s * devinf_content_type, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node, char *node);
47
48 static sync_agent_pb_error_e __append_cred_to_wbxml_node(cred_s * cred, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node);
49
50 static sync_agent_pb_error_e _oma_ds_binder_devinf_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
51 static sync_agent_pb_error_e _oma_ds_binder_syncml_start_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
52 static sync_agent_pb_error_e _oma_ds_binder_header_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
53 static sync_agent_pb_error_e _oma_ds_binder_final_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
54 static sync_agent_pb_error_e _oma_ds_binder_body_start_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
55 static sync_agent_pb_error_e _oma_ds_binder_status_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
56 static sync_agent_pb_error_e _oma_ds_binder_alert_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
57 static sync_agent_pb_error_e _oma_ds_binder_results_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
58 static sync_agent_pb_error_e _oma_ds_binder_put_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
59 static sync_agent_pb_error_e _oma_ds_binder_get_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
60 static sync_agent_pb_error_e _oma_ds_binder_sync_start_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
61 static sync_agent_pb_error_e _oma_ds_binder_sync_end_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
62 static sync_agent_pb_error_e _oma_ds_binder_add_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
63 static sync_agent_pb_error_e _oma_ds_binder_replace_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
64 static sync_agent_pb_error_e _oma_ds_binder_delete_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
65 static sync_agent_pb_error_e _oma_ds_binder_map_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node);
66
67 static protocol_version_e __get_oma_ds_protocol_version(char *verdtd);
68 static devinf_version_e __get_oma_ds_devInf_version(char *verdtd);
69 static devinf_devtyp_e __get_oma_ds_devInf_device_type(char *dev_type);
70 static devinf_content_type_s *__get_devinf_contenttype(WBXMLTreeNode * node);
71 static location_s *_get_location(WBXMLTreeNode * node);
72 static anchor_s *_get_anchor(WBXMLTreeNode * node);
73 static cred_s *__get_cred(WBXMLTreeNode * node);
74 static chal_s *_get_chal(WBXMLTreeNode * node);
75
76 static sync_agent_pb_error_e _oma_ds_binder_devinf_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
77 static sync_agent_pb_error_e _oma_ds_binder_header_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
78 static sync_agent_pb_error_e _oma_ds_binder_results_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
79 static sync_agent_pb_error_e _oma_ds_binder_put_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
80 static sync_agent_pb_error_e _oma_ds_binder_get_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
81 static sync_agent_pb_error_e _oma_ds_binder_alert_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
82 static sync_agent_pb_error_e _oma_ds_binder_sync_end_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
83 static sync_agent_pb_error_e _oma_ds_binder_sync_start_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
84 static sync_agent_pb_error_e _oma_ds_binder_add_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
85 static sync_agent_pb_error_e _oma_ds_binder_replace_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
86 static sync_agent_pb_error_e _oma_ds_binder_delete_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
87 static sync_agent_pb_error_e _oma_ds_binder_final_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
88 static sync_agent_pb_error_e _oma_ds_binder_status_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content);
89
90 /*
91         PE_ADD,
92     PE_DELETE,
93     PE_REPLACE,
94     PE_ALERT,
95     PE_GET,
96     PE_MAP,
97     PE_PUT,
98     PE_RESULTS,
99     PE_STATUS,
100     PE_SYNC_START,
101     PE_SYNC_END,
102     PE_HEADER,
103     PE_FINAL
104
105     PE_COPY,
106     PE_EXEC,
107     PE_SEARCH,
108     PE_SEQUENCE_START,
109     PE_SEQUENCE_END,
110     PE_ATOMIC_START,
111     PE_ATOMIC_END,
112     PE_PUT_GET,
113     PE_CMD_GROUP,
114     PE_GENERIC,
115  */
116 const sync_agent_pb_function_info_s oma_ds_binder_function_info[] = {
117         {PE_SYNCML_START, "SyncML", _oma_ds_binder_syncml_start_converter_function, NULL, false},
118         {PE_SYNCML_END, "/SyncML", NULL, NULL, false},
119         {PE_HEADER, "SyncHdr", _oma_ds_binder_header_converter_function, _oma_ds_binder_header_reverse_converter_function, true},
120         {PE_BODY_START, "SyncBody", _oma_ds_binder_body_start_converter_function, NULL, false},
121         {PE_BODY_END, "/SyncBody", NULL, NULL, false},
122         {PE_FINAL, "Final", _oma_ds_binder_final_converter_function, _oma_ds_binder_final_reverse_converter_function, true},
123         {PE_ALERT, "Alert", _oma_ds_binder_alert_command_converter_function, _oma_ds_binder_alert_command_reverse_converter_function, true},
124         {PE_STATUS, "Status", _oma_ds_binder_status_converter_function, _oma_ds_binder_status_reverse_converter_function, true},
125         {PE_RESULTS_START, "Results", _oma_ds_binder_results_command_converter_function, _oma_ds_binder_results_command_reverse_converter_function, false},
126         {PE_RESULTS_END, "/Results", NULL, NULL, false},
127         {PE_PUT_START, "Put", _oma_ds_binder_put_command_converter_function, _oma_ds_binder_put_command_reverse_converter_function, false},
128         {PE_PUT_END, "/Put", NULL, NULL, false},
129         {PE_GET, "Get", _oma_ds_binder_get_command_converter_function, _oma_ds_binder_get_command_reverse_converter_function, true},
130         {PE_SYNC_START, "Sync", _oma_ds_binder_sync_start_command_converter_function, _oma_ds_binder_sync_start_command_reverse_converter_function, false},
131         {PE_SYNC_END, "/Sync", _oma_ds_binder_sync_end_command_converter_function, _oma_ds_binder_sync_end_command_reverse_converter_function, false},
132         {PE_ADD, "Add", _oma_ds_binder_add_command_converter_function, _oma_ds_binder_add_command_reverse_converter_function, true},
133         {PE_REPLACE, "Replace", _oma_ds_binder_replace_command_converter_function, _oma_ds_binder_replace_command_reverse_converter_function, true},
134         {PE_DELETE, "Delete", _oma_ds_binder_delete_command_converter_function, _oma_ds_binder_delete_command_reverse_converter_function, true},
135         {PE_MAP, "Map", _oma_ds_binder_map_command_converter_function, NULL, true},
136         {PE_DEVINF, "DevInf", _oma_ds_binder_devinf_converter_function, _oma_ds_binder_devinf_reverse_converter_function, true}
137 };
138
139 static sync_agent_pb_error_e __append_location_to_wbxml_node(location_s * location, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node)
140 {
141         _INNER_FUNC_ENTER;
142
143         retvm_if(location == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "location is NULL");
144
145         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
146
147         if (location->loc_uri != NULL) {
148                 WBXMLTreeNode *LocURI = sync_agent_add_child_text_node(binder,
149                                                                        parent_node, ELEMENT_LOCURI, location->loc_uri, strlen(location->loc_uri));
150                 if (LocURI == NULL) {
151                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
152                         goto error;
153                 }
154         } else {
155                 /* error case */
156         }
157
158         if (location->loc_name != NULL) {
159                 WBXMLTreeNode *locName = sync_agent_add_child_text_node(binder,
160                                                                         parent_node, ELEMENT_LOCNAME, location->loc_name, strlen(location->loc_name));
161                 if (locName == NULL) {
162                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
163                         goto error;
164                 }
165         }
166
167  error:
168
169         _INNER_FUNC_EXIT;
170         return err;
171 }
172
173 static sync_agent_pb_error_e __append_anchor_to_wbxml_node(anchor_s * anchor, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node)
174 {
175         _INNER_FUNC_ENTER;
176
177         retvm_if(anchor == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "anchor is NULL");
178
179         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
180
181         WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, parent_node, ELEMENT_META);
182         if (meta_node == NULL) {
183                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
184                 goto error;
185         }
186
187         WBXMLTreeNode *anchor_node = sync_agent_add_child_node(binder, meta_node, ELEMENT_ANCHOR);
188         if (anchor_node == NULL) {
189                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
190                 goto error;
191         }
192
193         if (anchor->last_anchor != NULL) {
194                 WBXMLTreeNode *last_node = sync_agent_add_child_text_node(binder,
195                                                                           anchor_node, ELEMENT_LAST, anchor->last_anchor, strlen(anchor->last_anchor));
196                 if (last_node == NULL) {
197                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
198                         goto error;
199                 }
200         }
201
202         if (anchor->next_anchor != NULL) {
203                 WBXMLTreeNode *next_node = sync_agent_add_child_text_node(binder,
204                                                                           anchor_node, ELEMENT_NEXT, anchor->next_anchor, strlen(anchor->next_anchor));
205                 if (next_node == NULL) {
206                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
207                         goto error;
208                 }
209         }
210
211  error:
212
213         _INNER_FUNC_EXIT;
214         return err;
215 }
216
217 static sync_agent_pb_error_e __append_devinf_contenttype_to_wbxml_node(devinf_content_type_s * devinf_content_type, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node, char *node)
218 {
219         _INNER_FUNC_ENTER;
220
221         retvm_if(devinf_content_type == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "devinf_content_type is NULL");
222
223         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
224         WBXMLTreeNode *xnode = sync_agent_add_child_node(binder, parent_node, node);
225         if (xnode == NULL) {
226                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
227                 goto error;
228         }
229
230         WBXMLTreeNode *cttype_node = sync_agent_add_child_text_node(binder,
231                                                                     xnode, "CTType", devinf_content_type->ct_type, strlen(devinf_content_type->ct_type));
232         if (cttype_node == NULL) {
233                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
234                 goto error;
235         }
236
237         WBXMLTreeNode *verct_node = sync_agent_add_child_text_node(binder,
238                                                                    xnode, "VerCT", devinf_content_type->verct, strlen(devinf_content_type->verct));
239         if (verct_node == NULL) {
240                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
241                 goto error;
242         }
243
244  error:
245         _INNER_FUNC_EXIT;
246         return err;
247 }
248
249 static sync_agent_pb_error_e __append_cred_to_wbxml_node(cred_s * cred, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node)
250 {
251         _INNER_FUNC_ENTER;
252
253         retvm_if(cred == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "cred is NULL");
254
255         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
256
257         /* check validity */
258         WBXMLTreeNode *cred_node = sync_agent_add_child_node(binder, parent_node, ELEMENT_CRED);
259         if (cred_node == NULL) {
260                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
261                 goto error;
262         }
263
264         WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, cred_node, ELEMENT_META);
265         if (meta_node == NULL) {
266                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
267                 goto error;
268         }
269
270         WBXMLTreeNode *type_node = NULL;
271
272         switch (cred->type) {
273         case AUTH_TYPE_BASIC:
274
275                 if (cred->format == FORMAT_TYPE_BASE64) {
276                         WBXMLTreeNode *format_node = sync_agent_add_child_text_node(binder,
277                                                                                     meta_node, ELEMENT_FORMAT, ELEMENT_FORMAT_BASE64, strlen(ELEMENT_FORMAT_BASE64));
278                         if (format_node == NULL) {
279                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
280                                 goto error;
281                         }
282                 }
283
284                 type_node = sync_agent_add_child_text_node(binder, meta_node, ELEMENT_TYPE, ELEMENT_AUTH_BASIC, strlen(ELEMENT_AUTH_BASIC));
285                 if (type_node == NULL) {
286                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
287                         goto error;
288                 }
289
290                 if (cred->data != NULL) {
291                         WBXMLTreeNode *data_node = sync_agent_add_child_text_node(binder,
292                                                                                   cred_node, ELEMENT_DATA, cred->data, strlen(cred->data));
293                         if (data_node == NULL) {
294                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
295                                 goto error;
296                         }
297                 }
298                 break;
299         case AUTH_TYPE_MD5:
300
301                 if (cred->format == FORMAT_TYPE_BASE64) {
302                         WBXMLTreeNode *format_node = sync_agent_add_child_text_node(binder,
303                                                                                     meta_node, ELEMENT_FORMAT, ELEMENT_FORMAT_BASE64, strlen(ELEMENT_FORMAT_BASE64));
304                         if (format_node == NULL) {
305                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
306                                 goto error;
307                         }
308                 }
309
310                 type_node = sync_agent_add_child_text_node(binder, meta_node, ELEMENT_TYPE, ELEMENT_AUTH_MD5, strlen(ELEMENT_AUTH_MD5));
311                 if (type_node == NULL) {
312                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
313                         goto error;
314                 }
315
316                 if (cred->data != NULL) {
317                         WBXMLTreeNode *data_node = sync_agent_add_child_text_node(binder,
318                                                                                   cred_node, ELEMENT_DATA, cred->data, strlen(cred->data));
319                         if (data_node == NULL) {
320                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
321                                 goto error;
322                         }
323                 }
324                 break;
325         default:
326                 break;
327         }
328
329  error:
330         _INNER_FUNC_EXIT;
331         return err;
332 }
333
334 static sync_agent_pb_error_e _oma_ds_binder_devinf_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
335 {
336         _INNER_FUNC_ENTER;
337
338         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
339
340         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
341
342         item_s *pItem = (item_s *) content;
343         devinf_s *pDevInf = pItem->private.devinf;
344
345         if (pItem != NULL) {
346                 WBXMLTreeNode *item_node = sync_agent_create_node(binder, ELEMENT_ITEM);
347                 if (item_node == NULL) {
348                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
349                         goto error;
350                 }
351
352                 WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, item_node, ELEMENT_SOURCE);
353                 if (source_node == NULL) {
354                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
355                         goto error;
356                 }
357
358                 err = __append_location_to_wbxml_node(pItem->source, binder, source_node);
359                 if (err != SYNC_AGENT_PB_RETURN_OK)
360                         goto error;
361
362                 WBXMLTreeNode *data_node = sync_agent_add_child_node(binder, item_node, ELEMENT_DATA);
363                 if (data_node == NULL) {
364                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
365                         goto error;
366                 }
367
368                 /* devinf language setting */
369                 sync_agent_switch_protocol(binder, SYNC_AGENT_PB_PROTOCOL_SYNCML_DEVINF12);
370                 WBXMLTree *devinf_tree = sync_agent_create_wbxml_tree(binder);
371                 if (devinf_tree == NULL) {
372                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
373                         goto error;
374                 }
375
376                 sync_agent_add_wbxml_tree_to_wbxml_node(data_node, devinf_tree);
377
378                 /* create root node of devinf tree */
379                 WBXMLTreeNode *devinf_node = sync_agent_create_node(binder, ELEMENT_DEVINF);
380                 if (devinf_node == NULL) {
381                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
382                         goto error;
383                 }
384
385                 sync_agent_set_wbxml_tree_root(devinf_tree, devinf_node);
386
387                 WBXMLTreeNode *verDTD_node = NULL;
388                 switch (pDevInf->version) {
389                 case DEVINF_VERSION_UNKNOWN:
390                         verDTD_node = sync_agent_add_child_node(binder, devinf_node, ELEMENT_VERDTD);
391                         break;
392                 case DEVINF_VERSION_10:
393                         verDTD_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_10, strlen(ELEMENT_VERDRD_10));
394                         break;
395                 case DEVINF_VERSION_11:
396                         verDTD_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_11, strlen(ELEMENT_VERDRD_11));
397                         break;
398                 case DEVINF_VERSION_12:
399                         verDTD_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_12, strlen(ELEMENT_VERDRD_12));
400                         break;
401                 }
402
403                 if (verDTD_node == NULL) {
404                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
405                         goto error;
406                 }
407
408                 WBXMLTreeNode *man_node = sync_agent_add_child_text_node(binder,
409                                                                          devinf_node, ELEMENT_MAN, pDevInf->manufacturer, strlen(pDevInf->manufacturer));
410                 if (man_node == NULL) {
411                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
412                         goto error;
413                 }
414
415                 WBXMLTreeNode *mod_node = sync_agent_add_child_text_node(binder,
416                                                                          devinf_node, ELEMENT_MOD, pDevInf->model, strlen(pDevInf->model));
417                 if (mod_node == NULL) {
418                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
419                         goto error;
420                 }
421
422                 if (pDevInf->oem != NULL) {
423                         WBXMLTreeNode *oem_node = sync_agent_add_child_text_node(binder,
424                                                                                  devinf_node, ELEMENT_OEM, pDevInf->oem, strlen(pDevInf->oem));
425                         if (oem_node == NULL) {
426                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
427                                 goto error;
428                         }
429                 }
430
431                 WBXMLTreeNode *FwV_node = sync_agent_add_child_text_node(binder,
432                                                                          devinf_node, ELEMENT_FWV, pDevInf->firmware_version, strlen(pDevInf->firmware_version));
433                 if (FwV_node == NULL) {
434                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
435                         goto error;
436                 }
437
438                 WBXMLTreeNode *SwV_node = sync_agent_add_child_text_node(binder,
439                                                                          devinf_node, ELEMENT_SWV, pDevInf->software_version, strlen(pDevInf->software_version));
440                 if (SwV_node == NULL) {
441                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
442                         goto error;
443                 }
444
445                 WBXMLTreeNode *HwV_node = sync_agent_add_child_text_node(binder,
446                                                                          devinf_node, ELEMENT_HWV, pDevInf->hardware_version, strlen(pDevInf->hardware_version));
447                 if (HwV_node == NULL) {
448                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
449                         goto error;
450                 }
451
452                 WBXMLTreeNode *devID_node = sync_agent_add_child_text_node(binder,
453                                                                            devinf_node, ELEMENT_DEVID, pDevInf->dev_id, strlen(pDevInf->dev_id));
454                 if (devID_node == NULL) {
455                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
456                         goto error;
457                 }
458
459                 WBXMLTreeNode *devTyp_node = NULL;
460                 switch (pDevInf->devtyp) {
461                 case DEVINF_DEVTYPE_UNKNOWN:
462                         devTyp_node = sync_agent_add_child_node(binder, devinf_node, ELEMENT_DEVTYP);
463                         break;
464                 case DEVINF_DEVTYPE_PAGER:
465                         devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_PAGER, strlen(ELEMENT_PAGER));
466                         break;
467                 case DEVINF_DEVTYPE_HANDHELD:
468                         devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_HANDHELD, strlen(ELEMENT_HANDHELD));
469                         break;
470                 case DEVINF_DEVTYPE_PDA:
471                         devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_PDA, strlen(ELEMENT_PDA));
472                         break;
473                 case DEVINF_DEVTYPE_PHONE:
474                         devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_PHONE, strlen(ELEMENT_PHONE));
475                         break;
476                 case DEVINF_DEVTYPE_SMARTPHONE:
477                         devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_SMARTPHONE, strlen(ELEMENT_SMARTPHONE));
478                         break;
479                 case DEVINF_DEVTYPE_SERVER:
480                         devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_SERVER, strlen(ELEMENT_SERVER));
481                         break;
482                 case DEVINF_DEVTYPE_WORKSTATION:
483                         devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_WORKSTATION, strlen(ELEMENT_WORKSTATION));
484                         break;
485                 }
486
487                 if (devTyp_node == NULL) {
488                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
489                         goto error;
490                 }
491
492                 if (pDevInf->supports_utc) {
493                         WBXMLTreeNode *supportUTC_node = sync_agent_add_child_node(binder,
494                                                                                    devinf_node, ELEMENT_UTC);
495                         if (supportUTC_node == NULL) {
496                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
497                                 goto error;
498                         }
499                 }
500
501                 if (pDevInf->supports_large_objs) {
502                         WBXMLTreeNode *supportLargeObjs_node = sync_agent_add_child_node(binder,
503                                                                                          devinf_node, ELEMENT_SUPPORTLARGEOBJS);
504                         if (supportLargeObjs_node == NULL) {
505                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
506                                 goto error;
507                         }
508                 }
509
510                 if (pDevInf->supports_number_of_changes) {
511                         WBXMLTreeNode *supportNumberOfChanges_node = sync_agent_add_child_node(binder,
512                                                                                                devinf_node, ELEMENT_SUPPORTNUMBEROFCHANGES);
513                         if (supportNumberOfChanges_node == NULL) {
514                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
515                                 goto error;
516                         }
517                 }
518
519                 GList *datastoreIter = NULL;
520                 devinf_datastore_s *devInfDataStore = NULL;
521                 for (datastoreIter = pDevInf->datastores; datastoreIter != NULL; datastoreIter = g_list_next(datastoreIter)) {
522                         devInfDataStore = datastoreIter->data;
523
524                         WBXMLTreeNode *datastore_node = sync_agent_add_child_node(binder,
525                                                                                   devinf_node, ELEMENT_DATASTORE);
526                         if (datastore_node == NULL) {
527                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
528                                 goto error;
529                         }
530
531                         WBXMLTreeNode *sourceRef_node = sync_agent_add_child_text_node(binder,
532                                                                                        datastore_node, ELEMENT_SOURCEREF, devInfDataStore->source_ref, strlen(devInfDataStore->source_ref));
533                         if (sourceRef_node == NULL) {
534                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
535                                 goto error;
536                         }
537
538                         if (devInfDataStore->display_name != NULL) {
539                                 WBXMLTreeNode *displayname_node = sync_agent_add_child_text_node(binder,
540                                                                                                  datastore_node, ELEMENT_DISPLAYNAME, devInfDataStore->display_name, strlen(devInfDataStore->display_name));
541                                 if (displayname_node == NULL) {
542                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
543                                         goto error;
544                                 }
545                         }
546
547                         if (devInfDataStore->max_guid_size) {
548                                 char *str_maxguidsize = g_strdup_printf("%u", devInfDataStore->max_guid_size);
549                                 if (str_maxguidsize == NULL) {
550                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
551                                         goto error;
552                                 }
553
554                                 WBXMLTreeNode *maxguidsize_node = sync_agent_add_child_text_node(binder,
555                                                                                                  datastore_node, ELEMENT_MAXGUIDSIZE, str_maxguidsize, strlen(str_maxguidsize));
556
557                                 if (str_maxguidsize != NULL)
558                                         free(str_maxguidsize);
559
560                                 if (maxguidsize_node == NULL) {
561                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
562                                         goto error;
563                                 }
564                         }
565
566                         __append_devinf_contenttype_to_wbxml_node(devInfDataStore->rx_pref, binder, datastore_node, ELEMENT_RX_PREF);
567                         if (err != SYNC_AGENT_PB_RETURN_OK)
568                                 goto error;
569
570                         GList *rxIter = NULL;
571                         devinf_content_type_s *devInfContentType = NULL;
572                         for (rxIter = devInfDataStore->rx; rxIter != NULL; rxIter = g_list_next(rxIter)) {
573                                 devInfContentType = rxIter->data;
574                                 __append_devinf_contenttype_to_wbxml_node(devInfContentType, binder, datastore_node, ELEMENT_RX);
575                                 if (err != SYNC_AGENT_PB_RETURN_OK)
576                                         goto error;
577                         }
578
579                         __append_devinf_contenttype_to_wbxml_node(devInfDataStore->tx_pref, binder, datastore_node, ELEMENT_TX_PREF);
580                         if (err != SYNC_AGENT_PB_RETURN_OK)
581                                 goto error;
582
583                         GList *txIter = NULL;
584                         for (txIter = devInfDataStore->tx; txIter != NULL; txIter = g_list_next(txIter)) {
585                                 devInfContentType = txIter->data;
586                                 __append_devinf_contenttype_to_wbxml_node(devInfContentType, binder, datastore_node, ELEMENT_TX);
587                                 if (err != SYNC_AGENT_PB_RETURN_OK)
588                                         goto error;
589
590                         }
591
592                         GList *ctcapIter = NULL;
593                         devinf_ct_cap_s *devInfCTCap = NULL;
594                         for (ctcapIter = devInfDataStore->ct_caps; ctcapIter != NULL; ctcapIter = g_list_next(ctcapIter)) {
595                                 devInfCTCap = ctcapIter->data;
596
597                                 WBXMLTreeNode *ctcap_node = sync_agent_add_child_node(binder,
598                                                                                       datastore_node, ELEMENT_CTCAP);
599                                 if (ctcap_node == NULL) {
600                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
601                                         goto error;
602                                 }
603
604                                 WBXMLTreeNode *cttype_node = sync_agent_add_child_text_node(binder,
605                                                                                             ctcap_node, ELEMENT_CTTYPE, devInfCTCap->ct->ct_type, strlen(devInfCTCap->ct->ct_type));
606                                 if (cttype_node == NULL) {
607                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
608                                         goto error;
609                                 }
610
611                                 WBXMLTreeNode *verct_node = sync_agent_add_child_text_node(binder,
612                                                                                            ctcap_node, ELEMENT_VERCT, devInfCTCap->ct->verct, strlen(devInfCTCap->ct->verct));
613                                 if (verct_node == NULL) {
614                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
615                                         goto error;
616                                 }
617
618                                 /*TODO FieldLevel */
619
620                                 GList *propertyIter = NULL;
621                                 devinf_property_s *devInfProperty = NULL;
622                                 for (propertyIter = devInfCTCap->properties; propertyIter != NULL; propertyIter = g_list_next(propertyIter)) {
623                                         devInfProperty = propertyIter->data;
624
625                                         WBXMLTreeNode *property_node = sync_agent_add_child_node(binder,
626                                                                                                  ctcap_node, ELEMENT_PROPERTY);
627                                         if (property_node == NULL) {
628                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
629                                                 goto error;
630                                         }
631
632                                         WBXMLTreeNode *propname_node = sync_agent_add_child_text_node(binder,
633                                                                                                       property_node, ELEMENT_PROPNAME, devInfProperty->prop_name, strlen(devInfProperty->prop_name));
634                                         if (propname_node == NULL) {
635                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
636                                                 goto error;
637                                         }
638
639                                         if (devInfProperty->data_type != NULL) {
640                                                 WBXMLTreeNode *datatype_node = sync_agent_add_child_text_node(binder,
641                                                                                                               property_node, ELEMENT_DATATYPE, devInfProperty->data_type, strlen(devInfProperty->data_type));
642                                                 if (datatype_node == NULL) {
643                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
644                                                         goto error;
645                                                 }
646                                         }
647
648                                         if (devInfProperty->max_occur) {
649                                                 char *str_maxoccur = g_strdup_printf("%u", devInfProperty->max_occur);
650                                                 if (str_maxoccur == NULL) {
651                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
652                                                         goto error;
653                                                 }
654
655                                                 WBXMLTreeNode *maxoccur_node = sync_agent_add_child_text_node(binder,
656                                                                                                               property_node, ELEMENT_MAXOCCUR, str_maxoccur, strlen(str_maxoccur));
657
658                                                 if (str_maxoccur != NULL)
659                                                         free(str_maxoccur);
660
661                                                 if (maxoccur_node == NULL) {
662                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
663                                                         goto error;
664                                                 }
665                                         }
666
667                                         if (devInfProperty->max_size) {
668                                                 char *str_maxsize = g_strdup_printf("%u", devInfProperty->max_size);
669                                                 if (str_maxsize == NULL) {
670                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
671                                                         goto error;
672                                                 }
673
674                                                 WBXMLTreeNode *maxsize_node = sync_agent_add_child_text_node(binder,
675                                                                                                              property_node, ELEMENT_MAXSIZE, str_maxsize, strlen(str_maxsize));
676
677                                                 if (str_maxsize != NULL)
678                                                         free(str_maxsize);
679
680                                                 if (maxsize_node == NULL) {
681                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
682                                                         goto error;
683                                                 }
684                                         }
685
686                                         if (devInfProperty->no_truncate) {
687                                                 WBXMLTreeNode *notruncate_node = sync_agent_add_child_node(binder,
688                                                                                                            property_node, ELEMENT_NOTRUNCATE);
689                                                 if (notruncate_node == NULL) {
690                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
691                                                         goto error;
692                                                 }
693                                         }
694
695                                         GList *valenum = NULL;
696                                         char *val = NULL;
697                                         for (valenum = devInfProperty->val_enums; valenum != NULL; valenum = g_list_next(valenum)) {
698                                                 val = valenum->data;
699                                                 WBXMLTreeNode *valenum_node = sync_agent_add_child_text_node(binder,
700                                                                                                              property_node, ELEMENT_VALENUM, val, strlen(val));
701                                                 if (valenum_node == NULL) {
702                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
703                                                         goto error;
704                                                 }
705                                         }
706
707                                         if (devInfProperty->display_name != NULL) {
708                                                 WBXMLTreeNode *displayname_node = sync_agent_add_child_text_node(binder,
709                                                                                                                  property_node, ELEMENT_DISPLAYNAME, devInfProperty->display_name, strlen(devInfProperty->display_name));
710                                                 if (displayname_node == NULL) {
711                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
712                                                         goto error;
713                                                 }
714                                         }
715
716                                         GList *propparamIter = NULL;
717                                         devinf_prop_param_s *devInfPropParam = NULL;
718                                         for (propparamIter = devInfProperty->prop_params; propparamIter != NULL; propparamIter = g_list_next(propparamIter)) {
719                                                 devInfPropParam = propparamIter->data;
720
721                                                 WBXMLTreeNode *propparam_node = sync_agent_add_child_node(binder,
722                                                                                                           property_node, ELEMENT_PROPPARAM);
723                                                 if (propparam_node == NULL) {
724                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
725                                                         goto error;
726                                                 }
727
728                                                 WBXMLTreeNode *paramname_node = sync_agent_add_child_text_node(binder,
729                                                                                                                propparam_node, ELEMENT_PARAMNAME, devInfPropParam->param_name, strlen(devInfPropParam->param_name));
730                                                 if (paramname_node == NULL) {
731                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
732                                                         goto error;
733                                                 }
734
735                                                 if (devInfPropParam->data_type != NULL) {
736                                                         WBXMLTreeNode *datatype_node = sync_agent_add_child_text_node(binder,
737                                                                                                                       propparam_node, ELEMENT_DATATYPE, devInfPropParam->data_type, strlen(devInfPropParam->data_type));
738                                                         if (datatype_node == NULL) {
739                                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
740                                                                 goto error;
741                                                         }
742                                                 }
743
744                                                 valenum = NULL;
745                                                 val = NULL;
746                                                 for (valenum = devInfPropParam->val_enums; valenum != NULL; valenum = g_list_next(valenum)) {
747                                                         val = valenum->data;
748                                                         WBXMLTreeNode *valenum_node = sync_agent_add_child_text_node(binder,
749                                                                                                                      propparam_node, ELEMENT_VALENUM, val, strlen(val));
750                                                         if (valenum_node == NULL) {
751                                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
752                                                                 goto error;
753                                                         }
754                                                 }
755
756                                                 if (devInfPropParam->display_name != NULL) {
757                                                         WBXMLTreeNode *displayname_node = sync_agent_add_child_text_node(binder,
758                                                                                                                          propparam_node, ELEMENT_DISPLAYNAME, devInfPropParam->display_name, strlen(devInfPropParam->display_name));
759                                                         if (displayname_node == NULL) {
760                                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
761                                                                 goto error;
762                                                         }
763                                                 }
764                                         }
765                                 }
766                         }
767
768                         /* DSMem */
769                         WBXMLTreeNode *dsmem_node = sync_agent_add_child_node(binder,
770                                                                               datastore_node, ELEMENT_DSMEM);
771                         if (dsmem_node == NULL) {
772                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
773                                 goto error;
774                         }
775
776                         if (devInfDataStore->shared_mem) {
777                                 WBXMLTreeNode *sharedmem_node = sync_agent_add_child_node(binder,
778                                                                                           dsmem_node, ELEMENT_SHAREDMEM);
779                                 if (sharedmem_node == NULL) {
780                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
781                                         goto error;
782                                 }
783                         }
784
785                         if (devInfDataStore->max_mem) {
786                                 char *str_maxmem = g_strdup_printf("%u", devInfDataStore->max_mem);
787                                 WBXMLTreeNode *maxmem_node = sync_agent_add_child_text_node(binder,
788                                                                                             dsmem_node, ELEMENT_MAXMEM, str_maxmem, strlen(str_maxmem));
789
790                                 if (str_maxmem != NULL)
791                                         free(str_maxmem);
792
793                                 if (maxmem_node == NULL) {
794                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
795                                         goto error;
796                                 }
797                         }
798
799                         if (devInfDataStore->max_id) {
800                                 char *str_maxid = g_strdup_printf("%u", devInfDataStore->max_id);
801                                 WBXMLTreeNode *maxid_node = sync_agent_add_child_text_node(binder,
802                                                                                            dsmem_node, ELEMENT_MAXID, str_maxid, strlen(str_maxid));
803
804                                 if (str_maxid != NULL)
805                                         free(str_maxid);
806
807                                 if (maxid_node == NULL) {
808                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
809                                         goto error;
810                                 }
811                         }
812
813                         /* SupportHierarchicalSync */
814                         if (devInfDataStore->supports_hierarchical_sync) {
815                                 WBXMLTreeNode *supportshierarchicalsync_node = sync_agent_add_child_node(binder,
816                                                                                                          datastore_node, ELEMENT_SUPPORTHIERARCHICALSYNC);
817                                 if (supportshierarchicalsync_node == NULL) {
818                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
819                                         goto error;
820                                 }
821                         }
822
823                         WBXMLTreeNode *synccap_node = sync_agent_add_child_node(binder,
824                                                                                 datastore_node, ELEMENT_SYNCCAP);
825                         if (synccap_node == NULL) {
826                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
827                                 goto error;
828                         }
829
830                         if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_TWO_WAY)) {
831                                 WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder,
832                                                                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_1, strlen(ELEMENT_SYNCTYPE_1));
833                                 if (synctype_node == NULL) {
834                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
835                                         goto error;
836                                 }
837                         }
838                         if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_SLOW_SYNC)) {
839                                 WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder,
840                                                                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_2, strlen(ELEMENT_SYNCTYPE_2));
841                                 if (synctype_node == NULL) {
842                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
843                                         goto error;
844                                 }
845                         }
846                         if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT)) {
847                                 WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder,
848                                                                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_3, strlen(ELEMENT_SYNCTYPE_3));
849                                 if (synctype_node == NULL) {
850                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
851                                         goto error;
852                                 }
853                         }
854                         if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT)) {
855                                 WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder,
856                                                                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_4, strlen(ELEMENT_SYNCTYPE_4));
857                                 if (synctype_node == NULL) {
858                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
859                                         goto error;
860                                 }
861                         }
862                         if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER)) {
863                                 WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder,
864                                                                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_5, strlen(ELEMENT_SYNCTYPE_5));
865                                 if (synctype_node == NULL) {
866                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
867                                         goto error;
868                                 }
869                         }
870                         if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_SERVER)) {
871                                 WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder,
872                                                                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_6, strlen(ELEMENT_SYNCTYPE_6));
873                                 if (synctype_node == NULL) {
874                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
875                                         goto error;
876                                 }
877                         }
878                         if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC)) {
879                                 WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder,
880                                                                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_7, strlen(ELEMENT_SYNCTYPE_7));
881                                 if (synctype_node == NULL) {
882                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
883                                         goto error;
884                                 }
885                         }
886                         /*TODO filter-rx, filterCap */
887                 }
888                 sync_agent_undo_switch_protocol(binder);
889                 *wbxml_dom_node = item_node;
890         }
891
892  error:
893         _INNER_FUNC_EXIT;
894         return err;
895 }
896
897 static sync_agent_pb_error_e _oma_ds_binder_syncml_start_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
898 {
899         _INNER_FUNC_ENTER;
900
901         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
902         WBXMLTreeNode *syncml_node = sync_agent_create_node(binder, ELEMENT_SYNCML);
903         if (syncml_node == NULL) {
904                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
905                 goto error;
906         }
907
908         *wbxml_dom_node = syncml_node;
909
910  error:
911         _INNER_FUNC_EXIT;
912         return err;
913 }
914
915 static sync_agent_pb_error_e _oma_ds_binder_header_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
916 {
917         _INNER_FUNC_ENTER;
918
919         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
920
921         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
922         sync_hdr_s *pSyncHdr = (sync_hdr_s *) content;
923
924         /* add SyncHdr, VerDTD, VerProto node */
925         WBXMLTreeNode *synchdr_node = sync_agent_create_node(binder, ELEMENT_SYNCHDR);
926         if (synchdr_node == NULL) {
927                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
928                 goto error;
929         }
930
931         char *verDTD = ELEMENT_VERDTD;
932         char *verProto = ELEMENT_VERPROTO;
933
934         char *verDTD_data = NULL;
935         char *verProto_data = NULL;
936         if (pSyncHdr->version == VERSION_10) {
937                 verDTD_data = ELEMENT_VERDRD_10;
938                 verProto_data = ELEMENT_VERPROTO_10;
939         } else if (pSyncHdr->version == VERSION_11) {
940                 verDTD_data = ELEMENT_VERDRD_11;
941                 verProto_data = ELEMENT_VERPROTO_11;
942         } else if (pSyncHdr->version == VERSION_12) {
943                 verDTD_data = ELEMENT_VERDRD_12;
944                 verProto_data = ELEMENT_VERPROTO_12;
945         }
946
947         if (verDTD_data == NULL || verProto_data == NULL) {
948                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
949                 goto error;
950         }
951
952         WBXMLTreeNode *verdtd_node = sync_agent_add_child_text_node(binder,
953                                                                     synchdr_node, verDTD, verDTD_data, strlen(verDTD_data));
954         if (verdtd_node == NULL) {
955                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
956                 goto error;
957         }
958
959         WBXMLTreeNode *verProto_node = sync_agent_add_child_text_node(binder,
960                                                                       synchdr_node, verProto, verProto_data, strlen(verProto_data));
961         if (verProto_node == NULL) {
962                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
963                 goto error;
964         }
965
966         /* session ID */
967         WBXMLTreeNode *sessionID_node = NULL;
968         if (pSyncHdr->session_id != NULL)
969                 sessionID_node = sync_agent_add_child_text_node(binder, synchdr_node, ELEMENT_SESSIONID, pSyncHdr->session_id, strlen(pSyncHdr->session_id));
970         else
971                 sessionID_node = sync_agent_add_child_node(binder, synchdr_node, ELEMENT_SESSIONID);
972
973         if (sessionID_node == NULL) {
974                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
975                 goto error;
976         }
977
978         /* msgID */
979         char *msgID_data = g_strdup_printf("%u", pSyncHdr->message_id);
980         if (msgID_data == NULL) {
981                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
982                 goto error;
983         }
984
985         WBXMLTreeNode *msgID_node = sync_agent_add_child_text_node(binder,
986                                                                    synchdr_node, ELEMENT_MSGID, msgID_data, strlen(msgID_data));
987
988         if (msgID_data != NULL)
989                 free(msgID_data);
990
991         if (msgID_node == NULL) {
992                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
993                 goto error;
994         }
995
996         WBXMLTreeNode *target_node = sync_agent_add_child_node(binder,
997                                                                synchdr_node, ELEMENT_TARGET);
998         if (target_node == NULL) {
999                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1000                 goto error;
1001         }
1002
1003         err = __append_location_to_wbxml_node(pSyncHdr->target, binder, target_node);
1004         if (err != SYNC_AGENT_PB_RETURN_OK) {
1005                 goto error;
1006         }
1007
1008         WBXMLTreeNode *source_node = sync_agent_add_child_node(binder,
1009                                                                synchdr_node, ELEMENT_SOURCE);
1010         if (source_node == NULL) {
1011                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1012                 goto error;
1013         }
1014
1015         err = __append_location_to_wbxml_node(pSyncHdr->source, binder, source_node);
1016         if (err != SYNC_AGENT_PB_RETURN_OK) {
1017                 goto error;
1018         }
1019
1020         if (pSyncHdr->response_uri != NULL) {
1021                 WBXMLTreeNode *respuri_node = sync_agent_add_child_text_node(binder,
1022                                                                              synchdr_node, ELEMENT_RESPURI, pSyncHdr->response_uri, strlen(pSyncHdr->response_uri));
1023                 if (respuri_node == NULL) {
1024                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1025                         goto error;
1026                 }
1027         }
1028
1029         if (pSyncHdr->no_response) {
1030                 WBXMLTreeNode *noResponse_node = sync_agent_add_child_node(binder,
1031                                                                            synchdr_node, ELEMENT_NORESP);
1032                 if (noResponse_node == NULL) {
1033                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1034                         goto error;
1035                 }
1036         }
1037
1038         if (pSyncHdr->cred != NULL) {
1039                 err = __append_cred_to_wbxml_node(pSyncHdr->cred, binder, synchdr_node);
1040                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1041                         goto error;
1042                 }
1043         }
1044
1045         char *meta = ELEMENT_META;
1046         if (pSyncHdr->max_msg_size != 0 || pSyncHdr->max_obj_size != 0) {
1047                 WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder,
1048                                                                      synchdr_node, meta);
1049                 if (meta_node == NULL) {
1050                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1051                         goto error;
1052                 }
1053
1054                 unsigned int maxmsgsize = pSyncHdr->max_msg_size;
1055                 unsigned int maxobjsize = pSyncHdr->max_obj_size;
1056
1057                 if (maxmsgsize != 0) {
1058                         char *str_maxmsgsize = g_strdup_printf("%u", maxmsgsize);
1059                         if (str_maxmsgsize == NULL) {
1060                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1061                                 goto error;
1062                         }
1063
1064                         WBXMLTreeNode *maxmsgsize_node = sync_agent_add_child_text_node(binder,
1065                                                                                         meta_node, ELEMENT_MAXMSGSIZE, str_maxmsgsize, strlen(str_maxmsgsize));
1066                         if (str_maxmsgsize != NULL)
1067                                 free(str_maxmsgsize);
1068
1069                         if (maxmsgsize_node == NULL) {
1070                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1071                                 goto error;
1072                         }
1073                 }
1074
1075                 if (maxobjsize != 0) {
1076                         char *str_maxobjsize = g_strdup_printf("%u", maxobjsize);
1077                         if (str_maxobjsize == NULL) {
1078                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1079                                 goto error;
1080                         }
1081
1082                         WBXMLTreeNode *maxobjsize_node = sync_agent_add_child_text_node(binder,
1083                                                                                         meta_node, ELEMENT_MAXOBJSIZE, str_maxobjsize, strlen(str_maxobjsize));
1084                         if (str_maxobjsize != NULL)
1085                                 free(str_maxobjsize);
1086
1087                         if (maxobjsize_node == NULL) {
1088                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1089                                 goto error;
1090                         }
1091                 }
1092         }
1093
1094         *wbxml_dom_node = synchdr_node;
1095         synchdr_node = NULL;
1096
1097  error:
1098
1099         if (synchdr_node != NULL)
1100                 sync_agent_destroy_wbxml_node(synchdr_node);
1101
1102         _INNER_FUNC_EXIT;
1103         return err;
1104 }
1105
1106 static sync_agent_pb_error_e _oma_ds_binder_final_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1107 {
1108         _INNER_FUNC_ENTER;
1109
1110         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1111
1112         WBXMLTreeNode *final_node = sync_agent_create_node(binder, "Final");
1113         if (final_node == NULL) {
1114                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1115                 goto error;
1116         }
1117
1118         *wbxml_dom_node = final_node;
1119
1120  error:
1121         _INNER_FUNC_EXIT;
1122         return err;
1123
1124 }
1125
1126 static sync_agent_pb_error_e _oma_ds_binder_body_start_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1127 {
1128         _INNER_FUNC_ENTER;
1129
1130         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1131
1132         WBXMLTreeNode *syncbody_node = sync_agent_create_node(binder, ELEMENT_SYNCBODY);
1133         if (syncbody_node == NULL) {
1134                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1135                 goto error;
1136         }
1137
1138         *wbxml_dom_node = syncbody_node;
1139
1140  error:
1141         _INNER_FUNC_EXIT;
1142         return err;
1143 }
1144
1145 static sync_agent_pb_error_e _oma_ds_binder_status_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1146 {
1147         _INNER_FUNC_ENTER;
1148
1149         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
1150
1151         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1152
1153         status_s *pStatus = (status_s *) content;
1154
1155         command_type_e type = pStatus->type;
1156
1157         char *str_cmdID = NULL;
1158         char *str_msgRef = NULL;
1159         char *str_cmdRef = NULL;
1160
1161         WBXMLTreeNode *status_node = sync_agent_create_node(binder, ELEMENT_STATUS);
1162         if (status_node == NULL) {
1163                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1164                 goto error;
1165         }
1166
1167         unsigned int cmdID = pStatus->cmd_id;
1168         str_cmdID = g_strdup_printf("%u", cmdID);
1169         if (str_cmdID == NULL) {
1170                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1171                 goto error;
1172         }
1173
1174         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
1175                                                                    status_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
1176         if (cmdid_node == NULL) {
1177                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1178                 goto error;
1179         }
1180
1181         unsigned int msgRef = pStatus->msg_ref;
1182         str_msgRef = g_strdup_printf("%u", msgRef);
1183         if (str_msgRef == NULL) {
1184                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1185                 goto error;
1186         }
1187
1188         WBXMLTreeNode *msgref_node = sync_agent_add_child_text_node(binder,
1189                                                                     status_node, ELEMENT_MSGREF, str_msgRef, strlen(str_msgRef));
1190         if (msgref_node == NULL) {
1191                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1192                 goto error;
1193         }
1194
1195         unsigned int cmdRef = pStatus->cmd_ref;
1196         str_cmdRef = g_strdup_printf("%u", cmdRef);
1197         if (str_cmdRef == NULL) {
1198                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1199                 goto error;
1200         }
1201
1202         WBXMLTreeNode *cmdref_node = sync_agent_add_child_text_node(binder,
1203                                                                     status_node, ELEMENT_CMDREF, str_cmdRef, strlen(str_cmdRef));
1204         if (cmdref_node == NULL) {
1205                 goto error;
1206         }
1207
1208         char *str_command = NULL;
1209         switch (type) {
1210         case COMMAND_TYPE_ALERT:
1211                 {
1212                         str_command = ELEMENT_ALERT;
1213                 }
1214                 break;
1215         case COMMAND_TYPE_SYNC_START:
1216                 {
1217                         str_command = ELEMENT_SYNC;
1218                 }
1219                 break;
1220         case COMMAND_TYPE_PUT:
1221                 {
1222                         str_command = ELEMENT_PUT;
1223                 }
1224                 break;
1225         case COMMAND_TYPE_HEADER:
1226                 {
1227                         str_command = ELEMENT_SYNCHDR;
1228                 }
1229                 break;
1230         case COMMAND_TYPE_ADD:
1231                 {
1232                         str_command = ELEMENT_ADD;
1233                 }
1234                 break;
1235         case COMMAND_TYPE_REPLACE:
1236                 {
1237                         str_command = ELEMENT_REPLACE;
1238                 }
1239                 break;
1240         case COMMAND_TYPE_DELETE:
1241                 {
1242                         str_command = ELEMENT_DELETE;
1243                 }
1244                 break;
1245         case COMMAND_TYPE_MAP:
1246                 {
1247                         str_command = ELEMENT_MAP;
1248                 }
1249                 break;
1250         case COMMAND_TYPE_GET:
1251                 {
1252                         str_command = ELEMENT_GET;
1253                 }
1254                 break;
1255         case COMMAND_TYPE_RESULTS:
1256                 {
1257                         str_command = ELEMENT_RESULTS;
1258                 }
1259                 break;
1260         default:
1261                 break;
1262         }
1263
1264         if (str_command == NULL) {
1265                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1266                 goto error;
1267         }
1268
1269         WBXMLTreeNode *command_node = sync_agent_add_child_text_node(binder,
1270                                                                      status_node, ELEMENT_CMD, str_command, strlen(str_command));
1271         if (command_node == NULL) {
1272                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1273                 goto error;
1274         }
1275
1276         if (pStatus->target_ref != NULL) {
1277                 WBXMLTreeNode *targetref_node = sync_agent_add_child_text_node(binder,
1278                                                                                status_node, ELEMENT_TARGETREF, pStatus->target_ref->loc_uri, strlen(pStatus->target_ref->loc_uri));
1279                 if (targetref_node == NULL) {
1280                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1281                         goto error;
1282                 }
1283         }
1284
1285         if (pStatus->source_ref != NULL) {
1286                 WBXMLTreeNode *sourceref_node = sync_agent_add_child_text_node(binder,
1287                                                                                status_node, ELEMENT_SOURCEREF, pStatus->source_ref->loc_uri, strlen(pStatus->source_ref->loc_uri));
1288                 if (sourceref_node == NULL) {
1289                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1290                         goto error;
1291                 }
1292         }
1293
1294         if (pStatus->cred != NULL) {
1295                 err = __append_cred_to_wbxml_node(pStatus->cred, binder, status_node);
1296                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1297                         goto error;
1298                 }
1299         }
1300
1301         if (pStatus->chal != NULL) {
1302                 /*TODO chal */
1303         }
1304
1305         WBXMLTreeNode *data_node = sync_agent_add_child_text_node(binder,
1306                                                                   status_node, ELEMENT_DATA, pStatus->data, strlen(pStatus->data));
1307         if (data_node == NULL) {
1308                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1309                 goto error;
1310         }
1311
1312         if (type == COMMAND_TYPE_ALERT) {
1313                 if (pStatus->item != NULL) {
1314                         WBXMLTreeNode *item_node = sync_agent_add_child_node(binder,
1315                                                                              status_node, ELEMENT_ITEM);
1316                         if (item_node == NULL) {
1317                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1318                                 goto error;
1319                         }
1320
1321                         WBXMLTreeNode *item_data_node = sync_agent_add_child_node(binder,
1322                                                                                   item_node, ELEMENT_DATA);
1323                         if (item_data_node == NULL) {
1324                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1325                                 goto error;
1326                         }
1327
1328                         WBXMLTreeNode *item_data_Anchor_node = sync_agent_add_child_node(binder,
1329                                                                                          item_data_node, ELEMENT_ANCHOR);
1330                         if (item_data_Anchor_node == NULL) {
1331                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1332                                 goto error;
1333                         }
1334
1335                         if (pStatus->item->anchor != NULL) {
1336                                 WBXMLTreeNode *item_data_Anchor_Next_node = sync_agent_add_child_text_node(binder,
1337                                                                                                            item_data_Anchor_node, ELEMENT_NEXT, pStatus->item->anchor->next_anchor,
1338                                                                                                            strlen(pStatus->item->anchor->next_anchor));
1339
1340                                 if (item_data_Anchor_Next_node == NULL) {
1341                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1342                                         goto error;
1343                                 }
1344                         }
1345                 }
1346         }
1347
1348         *wbxml_dom_node = status_node;
1349         status_node = NULL;
1350
1351  error:
1352
1353         if (status_node != NULL)
1354                 sync_agent_destroy_wbxml_node(status_node);
1355
1356         if (str_cmdID != NULL)
1357                 free(str_cmdID);
1358
1359         if (str_cmdRef != NULL)
1360                 free(str_cmdRef);
1361
1362         if (str_msgRef != NULL)
1363                 free(str_msgRef);
1364
1365         _INNER_FUNC_EXIT;
1366         return err;
1367 }
1368
1369 static sync_agent_pb_error_e _oma_ds_binder_alert_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1370 {
1371         _INNER_FUNC_ENTER;
1372
1373         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
1374
1375         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1376
1377         char *str_cmdID = NULL;
1378         char *str_alert_type = NULL;
1379
1380         WBXMLTreeNode *alert_node = NULL;
1381
1382         command_s *pCommand = (command_s *) content;
1383
1384         command_alert_private_s *pAlert = (command_alert_private_s *) (&(pCommand->private));
1385         if (pAlert == NULL) {
1386                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1387                 goto error;
1388         }
1389
1390         if (pAlert->type == ALERT_UNKNOWN) {
1391                 /* error case */
1392                 err = SYNC_AGENT_PB_RETURN_INVALID_INPUT_PARAMETER;
1393                 goto error;
1394         }
1395
1396         alert_node = sync_agent_create_node(binder, ELEMENT_ALERT);
1397         if (alert_node == NULL) {
1398                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1399                 goto error;
1400         }
1401
1402         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
1403         if (str_cmdID == NULL) {
1404                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1405                 goto error;
1406         }
1407
1408         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
1409                                                                    alert_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
1410         if (cmdid_node == NULL) {
1411                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1412                 goto error;
1413         }
1414
1415         if (pCommand->no_resp) {
1416                 WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder,
1417                                                                        alert_node, ELEMENT_NORESP);
1418                 if (noResp_node == NULL) {
1419                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1420                         goto error;
1421                 }
1422         }
1423
1424         if (pCommand->cred != NULL) {
1425                 err = __append_cred_to_wbxml_node(pCommand->cred, binder, alert_node);
1426                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1427                         goto error;
1428                 }
1429         }
1430
1431         str_alert_type = g_strdup_printf("%u", pAlert->type);
1432         if (str_alert_type == NULL) {
1433                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1434                 goto error;
1435         }
1436
1437         WBXMLTreeNode *data_node = sync_agent_add_child_text_node(binder,
1438                                                                   alert_node, ELEMENT_DATA, str_alert_type, strlen(str_alert_type));
1439         if (data_node == NULL) {
1440                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1441                 goto error;
1442         }
1443
1444         /* item */
1445         if (pCommand->source != NULL && pCommand->target != NULL) {
1446                 WBXMLTreeNode *item_node = sync_agent_add_child_node(binder,
1447                                                                      alert_node, ELEMENT_ITEM);
1448                 if (item_node == NULL) {
1449                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1450                         goto error;
1451                 }
1452
1453                 WBXMLTreeNode *target_node = sync_agent_add_child_node(binder,
1454                                                                        item_node, ELEMENT_TARGET);
1455                 if (target_node == NULL) {
1456                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1457                         goto error;
1458                 }
1459
1460                 err = __append_location_to_wbxml_node(pCommand->target, binder, target_node);
1461                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1462                         goto error;
1463                 }
1464
1465                 WBXMLTreeNode *source_node = sync_agent_add_child_node(binder,
1466                                                                        item_node, ELEMENT_SOURCE);
1467                 if (source_node == NULL) {
1468                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1469                         goto error;
1470                 }
1471
1472                 err = __append_location_to_wbxml_node(pCommand->source, binder, source_node);
1473                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1474                         goto error;
1475                 }
1476
1477                 if (pAlert->anchor != NULL) {
1478                         err = __append_anchor_to_wbxml_node(pAlert->anchor, binder, item_node);
1479                         if (err != SYNC_AGENT_PB_RETURN_OK) {
1480                                 goto error;
1481                         }
1482                 }
1483         }
1484
1485         *wbxml_dom_node = alert_node;
1486         alert_node = NULL;
1487
1488  error:
1489
1490         if (alert_node != NULL)
1491                 sync_agent_destroy_wbxml_node(alert_node);
1492
1493         if (str_cmdID != NULL)
1494                 free(str_cmdID);
1495
1496         if (str_alert_type != NULL)
1497                 free(str_alert_type);
1498
1499         _INNER_FUNC_EXIT;
1500         return err;
1501 }
1502
1503 static sync_agent_pb_error_e _oma_ds_binder_results_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1504 {
1505         _INNER_FUNC_ENTER;
1506
1507         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
1508
1509         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1510
1511         char *str_cmdID = NULL;
1512         char *str_cmdRef = NULL;
1513         char *str_msgRef = NULL;
1514         WBXMLTreeNode *results_node = NULL;
1515
1516         command_s *pCommand = (command_s *) content;
1517         command_results_private_s *pResults = (command_results_private_s *) (&(pCommand->private));
1518         if (pResults == NULL) {
1519                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1520                 goto error;
1521         }
1522
1523         if (pResults->item == NULL) {
1524                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1525                 goto error;
1526         }
1527
1528         char *content_type = (pResults->item)->content_type;
1529         if (content_type == NULL) {
1530                 /* error case */
1531                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1532                 goto error;
1533         }
1534
1535         results_node = sync_agent_create_node(binder, ELEMENT_RESULTS);
1536         if (results_node == NULL) {
1537                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1538                 goto error;
1539         }
1540
1541         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
1542         if (str_cmdID != NULL) {
1543                 WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
1544                                                                            results_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
1545                 if (cmdid_node == NULL) {
1546                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1547                         goto error;
1548                 }
1549         }
1550
1551         if (pResults->msg_ref) {
1552                 str_msgRef = g_strdup_printf("%u", pResults->msg_ref);
1553                 if (str_msgRef == NULL) {
1554                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1555                         goto error;
1556                 }
1557
1558                 WBXMLTreeNode *msgref_node = sync_agent_add_child_text_node(binder,
1559                                                                             results_node, ELEMENT_MSGREF, str_msgRef, strlen(str_msgRef));
1560                 if (msgref_node == NULL) {
1561                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1562                         goto error;
1563                 }
1564         }
1565
1566         str_cmdRef = g_strdup_printf("%u", pResults->cmd_ref);
1567         if (str_cmdRef == NULL) {
1568                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1569                 goto error;
1570         }
1571
1572         WBXMLTreeNode *msgref_node = sync_agent_add_child_text_node(binder,
1573                                                                     results_node, ELEMENT_CMDREF, str_cmdRef, strlen(str_cmdRef));
1574         if (msgref_node == NULL) {
1575                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1576                 goto error;
1577         }
1578
1579         if (content_type != NULL) {
1580                 WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder,
1581                                                                      results_node, ELEMENT_META);
1582                 if (meta_node == NULL) {
1583                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1584                         goto error;
1585                 }
1586
1587                 WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder,
1588                                                                           meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
1589                 if (type_node == NULL) {
1590                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1591                         goto error;
1592                 }
1593         }
1594
1595         if (pResults->target_ref != NULL) {
1596                 WBXMLTreeNode *targetref_node = sync_agent_add_child_text_node(binder,
1597                                                                                results_node, ELEMENT_TARGETREF, pResults->target_ref->loc_uri, strlen(pResults->target_ref->loc_uri));
1598                 if (targetref_node == NULL) {
1599                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1600                         goto error;
1601                 }
1602         }
1603
1604         *wbxml_dom_node = results_node;
1605         results_node = NULL;
1606
1607  error:
1608
1609         if (results_node != NULL)
1610                 sync_agent_destroy_wbxml_node(results_node);
1611
1612         if (str_cmdID != NULL)
1613                 free(str_cmdID);
1614
1615         if (str_cmdRef != NULL)
1616                 free(str_cmdRef);
1617
1618         if (str_msgRef != NULL)
1619                 free(str_msgRef);
1620
1621         _INNER_FUNC_EXIT;
1622         return err;
1623 }
1624
1625 static sync_agent_pb_error_e _oma_ds_binder_put_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1626 {
1627         _INNER_FUNC_ENTER;
1628
1629         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
1630
1631         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1632
1633         char *str_cmdID = NULL;
1634         WBXMLTreeNode *put_node = NULL;
1635
1636         command_s *pCommand = (command_s *) content;
1637         command_access_private_s *pAccess = (command_access_private_s *) (&(pCommand->private));
1638         if (pAccess == NULL) {
1639                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1640                 goto error;
1641         }
1642
1643         char *content_type = (pAccess->item)->content_type;
1644         if (content_type == NULL) {
1645                 /* error case */
1646                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1647                 goto error;
1648         }
1649
1650         put_node = sync_agent_create_node(binder, ELEMENT_PUT);
1651         if (put_node == NULL) {
1652                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1653                 goto error;
1654         }
1655
1656         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
1657         if (str_cmdID == NULL) {
1658                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1659                 goto error;
1660         }
1661
1662         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
1663                                                                    put_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
1664         if (cmdid_node == NULL) {
1665                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1666                 goto error;
1667         }
1668
1669         if (pCommand->no_resp) {
1670                 WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder,
1671                                                                        put_node, ELEMENT_NORESP);
1672                 if (noResp_node == NULL) {
1673                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1674                         goto error;
1675                 }
1676         }
1677
1678         if (pCommand->cred != NULL) {
1679                 err = __append_cred_to_wbxml_node(pCommand->cred, binder, put_node);
1680                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1681                         goto error;
1682                 }
1683         }
1684
1685         if (content_type != NULL) {
1686                 WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder,
1687                                                                      put_node, ELEMENT_META);
1688                 if (meta_node == NULL) {
1689                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1690                         goto error;
1691                 }
1692
1693                 WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder,
1694                                                                           meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
1695                 if (type_node == NULL) {
1696                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1697                         goto error;
1698                 }
1699         }
1700
1701         *wbxml_dom_node = put_node;
1702         put_node = NULL;
1703
1704  error:
1705
1706         if (put_node != NULL)
1707                 sync_agent_destroy_wbxml_node(put_node);
1708
1709         if (str_cmdID != NULL)
1710                 free(str_cmdID);
1711
1712         _INNER_FUNC_EXIT;
1713         return err;
1714 }
1715
1716 static sync_agent_pb_error_e _oma_ds_binder_get_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1717 {
1718         _INNER_FUNC_ENTER;
1719
1720         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
1721
1722         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1723
1724         char *str_cmdID = NULL;
1725         WBXMLTreeNode *get_node = NULL;
1726
1727         command_s *pCommand = (command_s *) content;
1728         command_access_private_s *pAccess = (command_access_private_s *) (&(pCommand->private));
1729         if (pAccess == NULL) {
1730                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1731                 goto error;
1732         }
1733
1734         if (pAccess->item == NULL) {
1735                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1736                 goto error;
1737         }
1738
1739         char *content_type = (pAccess->item)->content_type;
1740         if (content_type == NULL) {
1741                 /* error case */
1742                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
1743                 goto error;
1744         }
1745
1746         get_node = sync_agent_create_node(binder, ELEMENT_GET);
1747
1748         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
1749         if (str_cmdID == NULL) {
1750                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1751                 goto error;
1752         }
1753
1754         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
1755                                                                    get_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
1756         if (cmdid_node == NULL) {
1757                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1758                 goto error;
1759         }
1760
1761         if (pCommand->no_resp) {
1762                 WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder,
1763                                                                        get_node, ELEMENT_NORESP);
1764                 if (noResp_node == NULL) {
1765                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1766                         goto error;
1767                 }
1768         }
1769
1770         if (pCommand->cred != NULL) {
1771                 err = __append_cred_to_wbxml_node(pCommand->cred, binder, get_node);
1772                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1773                         goto error;
1774                 }
1775         }
1776
1777         if (content_type != NULL) {
1778                 WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder,
1779                                                                      get_node, ELEMENT_META);
1780                 if (meta_node == NULL) {
1781                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1782                         goto error;
1783                 }
1784
1785                 WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder,
1786                                                                           meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
1787                 if (type_node == NULL) {
1788                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1789                         goto error;
1790                 }
1791         }
1792
1793         if (pAccess->item != NULL) {
1794                 WBXMLTreeNode *item_node = sync_agent_add_child_node(binder,
1795                                                                      get_node, ELEMENT_ITEM);
1796                 if (item_node == NULL) {
1797                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1798                         goto error;
1799                 }
1800
1801                 WBXMLTreeNode *target_node = sync_agent_add_child_node(binder,
1802                                                                        item_node, ELEMENT_TARGET);
1803                 if (target_node == NULL) {
1804                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1805                         goto error;
1806                 }
1807
1808                 err = __append_location_to_wbxml_node(pAccess->item->target, binder, target_node);
1809                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1810                         goto error;
1811                 }
1812         }
1813
1814         *wbxml_dom_node = get_node;
1815         get_node = NULL;
1816
1817  error:
1818
1819         if (get_node != NULL)
1820                 sync_agent_destroy_wbxml_node(get_node);
1821
1822         if (str_cmdID != NULL)
1823                 free(str_cmdID);
1824
1825         _INNER_FUNC_EXIT;
1826         return err;
1827 }
1828
1829 static sync_agent_pb_error_e _oma_ds_binder_sync_start_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1830 {
1831         _INNER_FUNC_ENTER;
1832
1833         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
1834
1835         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1836
1837         command_s *pCommand = (command_s *) content;
1838
1839         char *str_cmdID = NULL;
1840         char *numChanged_str = NULL;
1841         char *str_freemem = NULL;
1842         char *str_freeid = NULL;
1843
1844         WBXMLTreeNode *sync_node = sync_agent_create_node(binder, ELEMENT_SYNC);
1845         if (sync_node == NULL) {
1846                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1847                 goto error;
1848         }
1849
1850         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
1851         if (str_cmdID == NULL) {
1852                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1853                 goto error;
1854         }
1855
1856         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
1857                                                                    sync_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
1858         if (cmdid_node == NULL) {
1859                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1860                 goto error;
1861         }
1862
1863         if (pCommand->no_resp) {
1864                 WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder,
1865                                                                        sync_node, ELEMENT_NORESP);
1866                 if (noResp_node == NULL) {
1867                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1868                         goto error;
1869                 }
1870         }
1871
1872         if (pCommand->cred != NULL) {
1873                 err = __append_cred_to_wbxml_node(pCommand->cred, binder, sync_node);
1874                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1875                         goto error;
1876                 }
1877         }
1878
1879         if (pCommand->source != NULL && pCommand->target != NULL) {
1880                 WBXMLTreeNode *target_node = sync_agent_add_child_node(binder,
1881                                                                        sync_node, ELEMENT_TARGET);
1882                 if (target_node == NULL) {
1883                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1884                         goto error;
1885                 }
1886
1887                 err = __append_location_to_wbxml_node(pCommand->target, binder, target_node);
1888                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1889                         goto error;
1890                 }
1891
1892                 WBXMLTreeNode *source_node = sync_agent_add_child_node(binder,
1893                                                                        sync_node, ELEMENT_SOURCE);
1894                 if (source_node == NULL) {
1895                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1896                         goto error;
1897                 }
1898
1899                 err = __append_location_to_wbxml_node(pCommand->source, binder, source_node);
1900                 if (err != SYNC_AGENT_PB_RETURN_OK) {
1901                         goto error;
1902                 }
1903
1904         }
1905
1906         /* Mem */
1907         if (pCommand->private.sync.mem != NULL) {
1908                 WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, sync_node, ELEMENT_META);
1909                 if (meta_node == NULL) {
1910                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1911                         goto error;
1912                 }
1913
1914                 WBXMLTreeNode *mem_node = sync_agent_add_child_node(binder, meta_node, ELEMENT_MEM);
1915                 if (mem_node == NULL) {
1916                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1917                         goto error;
1918                 }
1919
1920                 if (pCommand->private.sync.mem->sharedmem) {
1921                         WBXMLTreeNode *sharedmem_node = sync_agent_add_child_node(binder, mem_node, ELEMENT_SHAREDMEM);
1922                         if (sharedmem_node == NULL) {
1923                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1924                                 goto error;
1925                         }
1926                 }
1927
1928                 if (pCommand->private.sync.mem->free_mem) {
1929                         str_freemem = g_strdup_printf("%u", pCommand->private.sync.mem->free_mem);
1930                         WBXMLTreeNode *freemem_node = sync_agent_add_child_text_node(binder,
1931                                                                                      mem_node, ELEMENT_FREEMEM, str_freemem, strlen(str_freemem));
1932                         if (freemem_node == NULL) {
1933                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1934                                 goto error;
1935                         }
1936                 }
1937
1938                 if (pCommand->private.sync.mem->free_id) {
1939                         str_freeid = g_strdup_printf("%u", pCommand->private.sync.mem->free_id);
1940                         WBXMLTreeNode *freeid_node = sync_agent_add_child_text_node(binder,
1941                                                                                     mem_node, ELEMENT_FREEID, str_freeid, strlen(str_freeid));
1942                         if (freeid_node == NULL) {
1943                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1944                                 goto error;
1945                         }
1946                 }
1947         }
1948
1949         if (pCommand->private.sync.has_num_changed) {
1950                 numChanged_str = g_strdup_printf("%u", pCommand->private.sync.num_changed);
1951                 if (numChanged_str == NULL) {
1952                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1953                         goto error;
1954                 }
1955
1956                 WBXMLTreeNode *numberOfChanges_node = sync_agent_add_child_text_node(binder,
1957                                                                                      sync_node, ELEMENT_NUMBEROFCHANGES, numChanged_str, strlen(numChanged_str));
1958                 if (numberOfChanges_node == NULL) {
1959                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
1960                         goto error;
1961                 }
1962         }
1963
1964         *wbxml_dom_node = sync_node;
1965         sync_node = NULL;
1966
1967  error:
1968
1969         if (sync_node != NULL)
1970                 sync_agent_destroy_wbxml_node(sync_node);
1971
1972         if (str_cmdID != NULL)
1973                 free(str_cmdID);
1974
1975         if (numChanged_str != NULL)
1976                 free(numChanged_str);
1977
1978         if (str_freemem != NULL)
1979                 free(str_freemem);
1980
1981         _INNER_FUNC_EXIT;
1982         return err;
1983 }
1984
1985 static sync_agent_pb_error_e _oma_ds_binder_sync_end_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1986 {
1987         _INNER_FUNC_ENTER;
1988
1989         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
1990
1991         _EXTERN_FUNC_EXIT;
1992
1993         return err;
1994 }
1995
1996 static sync_agent_pb_error_e _oma_ds_binder_add_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
1997 {
1998         _INNER_FUNC_ENTER;
1999
2000         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
2001
2002         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2003
2004         char *str_cmdID = NULL;
2005         char *str_size = NULL;
2006         WBXMLTreeNode *add_node = NULL;
2007
2008         command_s *pCommand = (command_s *) content;
2009
2010         command_change_private_s *pChange = (command_change_private_s *) (&(pCommand->private));
2011         if (pChange == NULL) {
2012                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
2013                 goto error;
2014         }
2015
2016         add_node = sync_agent_create_node(binder, ELEMENT_ADD);
2017         if (add_node == NULL) {
2018                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2019                 goto error;
2020         }
2021
2022         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
2023         if (str_cmdID == NULL) {
2024                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2025                 goto error;
2026         }
2027
2028         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
2029                                                                    add_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
2030         if (cmdid_node == NULL) {
2031                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2032                 goto error;
2033         }
2034
2035         if (pCommand->no_resp) {
2036                 WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder,
2037                                                                        add_node, ELEMENT_NORESP);
2038                 if (noResp_node == NULL) {
2039                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2040                         goto error;
2041                 }
2042         }
2043
2044         if (pCommand->cred != NULL) {
2045                 err = __append_cred_to_wbxml_node(pCommand->cred, binder, add_node);
2046                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2047                         goto error;
2048                 }
2049         }
2050
2051         GList *Iter = NULL;
2052         item_s *item = NULL;
2053         for (Iter = pChange->items; Iter != NULL; Iter = g_list_next(Iter)) {
2054                 item = (Iter->data);
2055
2056                 WBXMLTreeNode *item_node = sync_agent_add_child_node(binder,
2057                                                                      add_node, ELEMENT_ITEM);
2058                 if (item_node == NULL) {
2059                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2060                         goto error;
2061                 }
2062
2063                 if (item->source != NULL) {
2064                         WBXMLTreeNode *source_node = sync_agent_add_child_node(binder,
2065                                                                                item_node, ELEMENT_SOURCE);
2066                         if (source_node == NULL) {
2067                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2068                                 goto error;
2069                         }
2070
2071                         err = __append_location_to_wbxml_node(item->source, binder, source_node);
2072                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2073                                 goto error;
2074                         }
2075                 }
2076
2077                 if (item->target != NULL) {
2078                         WBXMLTreeNode *target_node = sync_agent_add_child_node(binder,
2079                                                                                item_node, ELEMENT_TARGET);
2080                         if (target_node == NULL) {
2081                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2082                                 goto error;
2083                         }
2084
2085                         err = __append_location_to_wbxml_node(item->target, binder, target_node);
2086                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2087                                 goto error;
2088                         }
2089                 }
2090
2091                 if (item->content_type != NULL) {
2092                         WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder,
2093                                                                              item_node, ELEMENT_META);
2094                         if (meta_node == NULL) {
2095                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2096                                 goto error;
2097                         }
2098
2099                         WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder,
2100                                                                                   meta_node, ELEMENT_TYPE, item->content_type, strlen(item->content_type));
2101                         if (type_node == NULL) {
2102                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2103                                 goto error;
2104                         }
2105
2106                         if (item->more_data) {
2107                                 if (item->size) {
2108                                         str_size = g_strdup_printf("%u", item->size);
2109                                         if (str_size == NULL) {
2110                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2111                                                 goto error;
2112                                         }
2113
2114                                         WBXMLTreeNode *size_node = sync_agent_add_child_text_node(binder,
2115                                                                                                   meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
2116                                         if (size_node == NULL) {
2117                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2118                                                 goto error;
2119                                         }
2120                                 }
2121                         }
2122                 }
2123
2124                 if (item->data_type == ITEM_DATA) {
2125                         if (item->private.data != NULL) {
2126                                 WBXMLTreeNode *data_node = sync_agent_add_child_cdata_node(binder,
2127                                                                                            item_node, ELEMENT_DATA, item->private.data, strlen(item->private.data));
2128                                 if (data_node == NULL) {
2129                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2130                                         goto error;
2131                                 }
2132                         }
2133                 }
2134
2135                 if (item->more_data) {
2136                         WBXMLTreeNode *moredata_node = sync_agent_add_child_node(binder,
2137                                                                                  item_node, ELEMENT_MOREDATA);
2138                         if (moredata_node == NULL) {
2139                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2140                                 goto error;
2141                         }
2142                 }
2143         }
2144
2145         *wbxml_dom_node = add_node;
2146         add_node = NULL;
2147
2148  error:
2149
2150         if (add_node != NULL)
2151                 sync_agent_destroy_wbxml_node(add_node);
2152
2153         if (str_cmdID != NULL)
2154                 free(str_cmdID);
2155
2156         if (str_size != NULL)
2157                 free(str_size);
2158
2159         _EXTERN_FUNC_EXIT;
2160         return err;
2161 }
2162
2163 static sync_agent_pb_error_e _oma_ds_binder_replace_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
2164 {
2165         _INNER_FUNC_ENTER;
2166
2167         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
2168
2169         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2170
2171         char *str_cmdID = NULL;
2172         char *str_size = NULL;
2173         WBXMLTreeNode *replace_node = NULL;
2174
2175         command_s *pCommand = (command_s *) content;
2176
2177         command_change_private_s *pChange = (command_change_private_s *) (&(pCommand->private));
2178
2179         if (pChange == NULL) {
2180                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
2181                 goto error;
2182         }
2183
2184         replace_node = sync_agent_create_node(binder, ELEMENT_REPLACE);
2185         if (replace_node == NULL) {
2186                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2187                 goto error;
2188         }
2189
2190         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
2191         if (str_cmdID == NULL) {
2192                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2193                 goto error;
2194         }
2195
2196         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
2197                                                                    replace_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
2198         if (cmdid_node == NULL) {
2199                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2200                 goto error;
2201         }
2202
2203         if (pCommand->no_resp) {
2204                 WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder,
2205                                                                        replace_node, ELEMENT_NORESP);
2206                 if (noResp_node == NULL) {
2207                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2208                         goto error;
2209                 }
2210         }
2211
2212         if (pCommand->cred != NULL) {
2213                 err = __append_cred_to_wbxml_node(pCommand->cred, binder, replace_node);
2214                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2215                         goto error;
2216                 }
2217         }
2218
2219         GList *Iter = NULL;
2220         item_s *item = NULL;
2221         for (Iter = pChange->items; Iter != NULL; Iter = g_list_next(Iter)) {
2222                 item = (Iter->data);
2223
2224                 WBXMLTreeNode *item_node = sync_agent_add_child_node(binder,
2225                                                                      replace_node, ELEMENT_ITEM);
2226                 if (item_node == NULL) {
2227                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2228                         goto error;
2229                 }
2230
2231                 if (item->source != NULL) {
2232                         WBXMLTreeNode *source_node = sync_agent_add_child_node(binder,
2233                                                                                item_node, ELEMENT_SOURCE);
2234                         if (source_node == NULL) {
2235                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2236                                 goto error;
2237                         }
2238                         err = __append_location_to_wbxml_node(item->source, binder, source_node);
2239                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2240                                 goto error;
2241                         }
2242                 }
2243
2244                 if (item->target != NULL) {
2245                         WBXMLTreeNode *target_node = sync_agent_add_child_node(binder,
2246                                                                                item_node, ELEMENT_TARGET);
2247                         if (target_node == NULL) {
2248                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2249                                 goto error;
2250                         }
2251                         err = __append_location_to_wbxml_node(item->target, binder, target_node);
2252                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2253                                 goto error;
2254                         }
2255                 }
2256
2257                 if (item->content_type != NULL) {
2258                         WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder,
2259                                                                              item_node, ELEMENT_META);
2260                         if (meta_node == NULL) {
2261                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2262                                 goto error;
2263                         }
2264
2265                         WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder,
2266                                                                                   meta_node, ELEMENT_TYPE, item->content_type, strlen(item->content_type));
2267                         if (type_node == NULL) {
2268                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2269                                 goto error;
2270                         }
2271
2272                         if (item->more_data) {
2273                                 if (item->size) {
2274                                         str_size = g_strdup_printf("%u", item->size);
2275                                         if (str_size == NULL) {
2276                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2277                                                 goto error;
2278                                         }
2279
2280                                         WBXMLTreeNode *size_node = sync_agent_add_child_text_node(binder,
2281                                                                                                   meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
2282                                         if (size_node == NULL) {
2283                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2284                                                 goto error;
2285                                         }
2286                                 }
2287                         }
2288                 }
2289
2290                 if (item->data_type == ITEM_DATA) {
2291                         if (item->private.data != NULL) {
2292                                 WBXMLTreeNode *data_node = sync_agent_add_child_cdata_node(binder,
2293                                                                                            item_node, ELEMENT_DATA, item->private.data, strlen(item->private.data));
2294                                 if (data_node == NULL) {
2295                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2296                                         goto error;
2297                                 }
2298                         }
2299                 }
2300
2301                 if (item->more_data) {
2302                         WBXMLTreeNode *moredata_node = sync_agent_add_child_node(binder,
2303                                                                                  item_node, ELEMENT_MOREDATA);
2304                         if (moredata_node == NULL) {
2305                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2306                                 goto error;
2307                         }
2308                 }
2309
2310         }
2311
2312         *wbxml_dom_node = replace_node;
2313         replace_node = NULL;
2314
2315  error:
2316
2317         if (replace_node != NULL)
2318                 sync_agent_destroy_wbxml_node(replace_node);
2319
2320         if (str_cmdID != NULL)
2321                 free(str_cmdID);
2322
2323         if (str_size != NULL)
2324                 free(str_size);
2325
2326         _EXTERN_FUNC_EXIT;
2327         return err;
2328 }
2329
2330 static sync_agent_pb_error_e _oma_ds_binder_delete_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
2331 {
2332         _INNER_FUNC_ENTER;
2333
2334         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
2335
2336         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2337
2338         char *str_cmdID = NULL;
2339         char *str_size = NULL;
2340         WBXMLTreeNode *delete_node = NULL;
2341
2342         command_s *pCommand = (command_s *) content;
2343
2344         command_change_private_s *pChange = (command_change_private_s *) (&(pCommand->private));
2345         if (pChange == NULL) {
2346                 err = SYNC_AGENT_PB_RETURN_NOT_DEFINED;
2347                 goto error;
2348         }
2349
2350         delete_node = sync_agent_create_node(binder, ELEMENT_DELETE);
2351         if (delete_node == NULL) {
2352                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2353                 goto error;
2354         }
2355
2356         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
2357         if (str_cmdID == NULL) {
2358                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2359                 goto error;
2360         }
2361
2362         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
2363                                                                    delete_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
2364         if (cmdid_node == NULL) {
2365                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2366                 goto error;
2367         }
2368
2369         if (pCommand->no_resp) {
2370                 WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder,
2371                                                                        delete_node, ELEMENT_NORESP);
2372                 if (noResp_node == NULL) {
2373                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2374                         goto error;
2375                 }
2376         }
2377
2378         /*TODO Archive */
2379         /*TODO sftDel */
2380
2381         if (pCommand->cred != NULL) {
2382                 err = __append_cred_to_wbxml_node(pCommand->cred, binder, delete_node);
2383                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2384                         goto error;
2385                 }
2386         }
2387
2388         GList *Iter = NULL;
2389         item_s *item = NULL;
2390         for (Iter = pCommand->private.change.items; Iter != NULL; Iter = g_list_next(Iter)) {
2391                 item = (Iter->data);
2392
2393                 WBXMLTreeNode *item_node = sync_agent_add_child_node(binder,
2394                                                                      delete_node, ELEMENT_ITEM);
2395                 if (item_node == NULL) {
2396                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2397                         goto error;
2398                 }
2399
2400                 if (item->source != NULL) {
2401                         WBXMLTreeNode *source_node = sync_agent_add_child_node(binder,
2402                                                                                item_node, ELEMENT_SOURCE);
2403                         if (source_node == NULL) {
2404                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2405                                 goto error;
2406                         }
2407
2408                         err = __append_location_to_wbxml_node(item->source, binder, source_node);
2409                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2410                                 goto error;
2411                         }
2412                 }
2413
2414                 if (item->target != NULL) {
2415                         WBXMLTreeNode *target_node = sync_agent_add_child_node(binder,
2416                                                                                item_node, ELEMENT_TARGET);
2417                         if (target_node == NULL) {
2418                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2419                                 goto error;
2420                         }
2421
2422                         err = __append_location_to_wbxml_node(item->target, binder, target_node);
2423                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2424                                 goto error;
2425                         }
2426                 }
2427
2428                 if (item->content_type != NULL) {
2429                         WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder,
2430                                                                              item_node, ELEMENT_META);
2431                         if (meta_node == NULL) {
2432                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2433                                 goto error;
2434                         }
2435
2436                         WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder,
2437                                                                                   meta_node, ELEMENT_TYPE, item->content_type, strlen(item->content_type));
2438                         if (type_node == NULL) {
2439                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2440                                 goto error;
2441                         }
2442
2443                         if (item->size) {
2444                                 str_size = g_strdup_printf("%u", item->size);
2445                                 if (str_size == NULL) {
2446                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2447                                         goto error;
2448                                 }
2449
2450                                 WBXMLTreeNode *size_node = sync_agent_add_child_text_node(binder,
2451                                                                                           meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
2452                                 if (size_node == NULL) {
2453                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2454                                         goto error;
2455                                 }
2456                         }
2457                 }
2458         }
2459
2460         *wbxml_dom_node = delete_node;
2461         delete_node = NULL;
2462
2463  error:
2464
2465         if (delete_node != NULL)
2466                 sync_agent_destroy_wbxml_node(delete_node);
2467
2468         if (str_cmdID != NULL)
2469                 free(str_cmdID);
2470
2471         if (str_size != NULL)
2472                 free(str_size);
2473
2474         _EXTERN_FUNC_EXIT;
2475         return err;
2476 }
2477
2478 static sync_agent_pb_error_e _oma_ds_binder_map_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node)
2479 {
2480         _INNER_FUNC_ENTER;
2481
2482         retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL");
2483
2484         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2485         char *str_cmdID = NULL;
2486
2487         command_s *pCommand = (command_s *) content;
2488
2489         WBXMLTreeNode *map_node = sync_agent_create_node(binder, ELEMENT_MAP);
2490         if (map_node == NULL) {
2491                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2492                 goto error;
2493         }
2494
2495         str_cmdID = g_strdup_printf("%u", pCommand->cmd_id);
2496         if (str_cmdID == NULL) {
2497                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2498                 goto error;
2499         }
2500
2501         WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder,
2502                                                                    map_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
2503         if (cmdid_node == NULL) {
2504                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2505                 goto error;
2506         }
2507
2508         if (pCommand->source != NULL && pCommand->target != NULL) {
2509                 WBXMLTreeNode *target_node = sync_agent_add_child_node(binder,
2510                                                                        map_node, ELEMENT_TARGET);
2511                 if (target_node == NULL) {
2512                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2513                         goto error;
2514                 }
2515
2516                 err = __append_location_to_wbxml_node(pCommand->target, binder, target_node);
2517                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2518                         goto error;
2519                 }
2520
2521                 WBXMLTreeNode *source_node = sync_agent_add_child_node(binder,
2522                                                                        map_node, ELEMENT_SOURCE);
2523                 if (source_node == NULL) {
2524                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2525                         goto error;
2526                 }
2527
2528                 err = __append_location_to_wbxml_node(pCommand->source, binder, source_node);
2529                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2530                         goto error;
2531                 }
2532         }
2533
2534         if (pCommand->cred != NULL) {
2535                 err = __append_cred_to_wbxml_node(pCommand->cred, binder, map_node);
2536                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2537                         goto error;
2538                 }
2539         }
2540
2541         GList *iter = NULL;
2542         item_s *item = NULL;
2543         for (iter = pCommand->private.map.items; iter != NULL; iter = g_list_next(iter)) {
2544                 item = iter->data;
2545                 WBXMLTreeNode *mapItem_node = sync_agent_add_child_node(binder,
2546                                                                         map_node, ELEMENT_MAPITEM);
2547                 if (mapItem_node == NULL) {
2548                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2549                         goto error;
2550                 }
2551
2552                 if (item->source != NULL && item->target != NULL) {
2553                         WBXMLTreeNode *item_target_node = sync_agent_add_child_node(binder,
2554                                                                                     mapItem_node, ELEMENT_TARGET);
2555                         if (item_target_node == NULL) {
2556                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2557                                 goto error;
2558                         }
2559
2560                         err = __append_location_to_wbxml_node(item->target, binder, item_target_node);
2561                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2562                                 goto error;
2563                         }
2564
2565                         WBXMLTreeNode *item_source_node = sync_agent_add_child_node(binder,
2566                                                                                     mapItem_node, ELEMENT_SOURCE);
2567                         if (item_source_node == NULL) {
2568                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2569                                 goto error;
2570                         }
2571
2572                         err = __append_location_to_wbxml_node(item->source, binder, item_source_node);
2573                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2574                                 goto error;
2575                         }
2576                 }
2577         }
2578
2579         *wbxml_dom_node = map_node;
2580         map_node = NULL;
2581
2582  error:
2583
2584         if (map_node != NULL)
2585                 sync_agent_destroy_wbxml_node(map_node);
2586
2587         if (str_cmdID != NULL)
2588                 free(str_cmdID);
2589
2590         _EXTERN_FUNC_EXIT;
2591         return err;
2592 }
2593
2594 static protocol_version_e __get_oma_ds_protocol_version(char *verdtd)
2595 {
2596         _INNER_FUNC_ENTER;
2597
2598         retvm_if(verdtd == NULL, VERSION_UNKNOWN, "verdtd is NULL");
2599
2600         protocol_version_e protocol_version = VERSION_UNKNOWN;
2601         if (strcmp(verdtd, ELEMENT_VERDRD_12) == 0) {
2602                 protocol_version = VERSION_12;
2603         } else if (strcmp(verdtd, ELEMENT_VERDRD_11) == 0) {
2604                 protocol_version = VERSION_11;
2605         } else if (strcmp(verdtd, ELEMENT_VERDRD_10) == 0) {
2606                 protocol_version = VERSION_10;
2607         }
2608
2609         _INNER_FUNC_EXIT;
2610         return protocol_version;
2611 }
2612
2613 static devinf_version_e __get_oma_ds_devInf_version(char *verdtd)
2614 {
2615         _INNER_FUNC_ENTER;
2616
2617         retvm_if(verdtd == NULL, DEVINF_VERSION_UNKNOWN, "verdtd is NULL");
2618
2619         devinf_version_e devInf_version = DEVINF_VERSION_UNKNOWN;
2620         if (strcmp(verdtd, ELEMENT_VERDRD_12) == 0) {
2621                 devInf_version = DEVINF_VERSION_12;
2622         } else if (strcmp(verdtd, ELEMENT_VERDRD_11) == 0) {
2623                 devInf_version = DEVINF_VERSION_11;
2624         } else if (strcmp(verdtd, ELEMENT_VERDRD_10) == 0) {
2625                 devInf_version = DEVINF_VERSION_10;
2626         }
2627
2628         _INNER_FUNC_EXIT;
2629         return devInf_version;
2630 }
2631
2632 static devinf_devtyp_e __get_oma_ds_devInf_device_type(char *dev_type)
2633 {
2634         _INNER_FUNC_ENTER;
2635
2636         retvm_if(dev_type == NULL, DEVINF_DEVTYPE_UNKNOWN, "dev_type is NULL");
2637
2638         devinf_devtyp_e device_type = DEVINF_DEVTYPE_UNKNOWN;
2639         if (strcmp(dev_type, ELEMENT_PAGER) == 0) {
2640                 device_type = DEVINF_DEVTYPE_PAGER;
2641         } else if (strcmp(dev_type, ELEMENT_HANDHELD) == 0) {
2642                 device_type = DEVINF_DEVTYPE_HANDHELD;
2643         } else if (strcmp(dev_type, ELEMENT_PDA) == 0) {
2644                 device_type = DEVINF_DEVTYPE_PDA;
2645         } else if (strcmp(dev_type, ELEMENT_PHONE) == 0) {
2646                 device_type = DEVINF_DEVTYPE_PHONE;
2647         } else if (strcmp(dev_type, ELEMENT_SMARTPHONE) == 0) {
2648                 device_type = DEVINF_DEVTYPE_SMARTPHONE;
2649         } else if (strcmp(dev_type, ELEMENT_SERVER) == 0) {
2650                 device_type = DEVINF_DEVTYPE_SERVER;
2651         } else if (strcmp(dev_type, ELEMENT_WORKSTATION) == 0) {
2652                 device_type = DEVINF_DEVTYPE_WORKSTATION;
2653         }
2654
2655         _INNER_FUNC_EXIT;
2656         return device_type;
2657 }
2658
2659 static devinf_content_type_s *__get_devinf_contenttype(WBXMLTreeNode * node)
2660 {
2661         _INNER_FUNC_ENTER;
2662
2663         retvm_if(node == NULL, NULL, "node is NULL");
2664
2665         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2666         devinf_content_type_s *devinf_content_type = NULL;
2667
2668         devinf_content_type = (devinf_content_type_s *) calloc(1, sizeof(devinf_content_type_s));
2669         if (devinf_content_type == NULL) {
2670                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2671                 _DEBUG_ERROR("devinf_content_type is null");
2672                 goto return_part;
2673         }
2674
2675         /* get first child */
2676         WBXMLTreeNode *child = node->children;
2677         for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {
2678         }
2679
2680         const char *first_child_name = NULL;
2681         if (child != NULL) {
2682                 first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
2683                 if (strcmp(first_child_name, ELEMENT_CTTYPE) == 0) {
2684                         char *ctType = NULL;
2685                         err = sync_agent_get_text_from_node(child, &ctType);
2686                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2687                                 goto return_part;
2688                         }
2689                         if (ctType != NULL)
2690                                 devinf_content_type->ct_type = strdup(ctType);
2691                 } else {
2692                         /* error */
2693                         goto return_part;
2694                 }
2695
2696                 /* get second child  */
2697                 child = child->next;
2698                 for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {
2699                 }
2700
2701                 if (child != NULL) {
2702                         const char *second_child_name = NULL;
2703                         second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
2704                         if (strcmp(second_child_name, ELEMENT_VERCT) == 0) {
2705                                 char *verCT = NULL;
2706                                 err = sync_agent_get_text_from_node(child, &verCT);
2707                                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2708                                         goto return_part;
2709                                 }
2710                                 if (verCT != NULL)
2711                                         devinf_content_type->verct = strdup(verCT);
2712                         } else {
2713                                 /* error */
2714                                 goto return_part;
2715                         }
2716                 }
2717         }
2718
2719         _INNER_FUNC_EXIT;
2720         return devinf_content_type;
2721
2722  return_part:
2723
2724         /* for prevent */
2725         if (devinf_content_type != NULL)
2726                 free(devinf_content_type);
2727
2728         _INNER_FUNC_EXIT;
2729         return NULL;
2730
2731 }
2732
2733 static location_s *_get_location(WBXMLTreeNode * node)
2734 {
2735         _INNER_FUNC_ENTER;
2736
2737         retvm_if(node == NULL, NULL, "node is NULL");
2738
2739         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2740         location_s *location = NULL;
2741
2742         WBXMLTreeNode *child = NULL;
2743
2744         char *locURI = NULL;
2745         char *locName = NULL;
2746
2747         /* get first child : required LocURI */
2748         child = node->children;
2749         for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {
2750         }
2751
2752         const char *first_child_name = NULL;
2753         if (child != NULL) {
2754                 first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
2755                 _DEBUG_TRACE("child_name = %s", first_child_name);
2756                 if (strcmp(first_child_name, ELEMENT_LOCURI) == 0) {
2757                         err = sync_agent_get_text_from_node(child, &locURI);
2758                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2759                                 goto return_part;
2760                         }
2761                 } else {
2762                         /* error */
2763                         goto return_part;
2764                 }
2765
2766                 /* get second child : optional LocName */
2767                 child = child->next;
2768                 for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {
2769                 }
2770
2771                 if (child != NULL) {
2772                         const char *second_child_name = NULL;
2773                         second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
2774                         _DEBUG_TRACE("child_name = %s", second_child_name);
2775                         if (strcmp(second_child_name, ELEMENT_LOCNAME) == 0) {
2776                                 err = sync_agent_get_text_from_node(child, &locName);
2777                                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2778                                         goto return_part;
2779                                 }
2780                         } else {
2781                                 /* error */
2782                                 goto return_part;
2783                         }
2784                 }
2785
2786                 sa_error_type_e error = create_location(locURI, locName, &location);
2787                 if (error != SA_INTERNAL_OK) {
2788                         _DEBUG_ERROR("create_location() failed !, error = %d", error);
2789                         goto return_part;
2790                 }
2791         }
2792
2793         _EXTERN_FUNC_EXIT;
2794         return location;
2795
2796  return_part:
2797
2798         _EXTERN_FUNC_EXIT;
2799         return NULL;
2800 }
2801
2802 static anchor_s *_get_anchor(WBXMLTreeNode * node)
2803 {
2804         _INNER_FUNC_ENTER;
2805
2806         retvm_if(node == NULL, NULL, "node is NULL");
2807
2808         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2809         anchor_s *anchor = NULL;
2810
2811         WBXMLTreeNode *child = NULL;
2812
2813         char *lastAnchor = NULL;
2814         char *nextAnchor = NULL;
2815         /* get first child : optional lastAnchor */
2816         child = node->children;
2817         for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {
2818         }
2819
2820         const char *first_child_name = NULL;
2821         if (child != NULL) {
2822                 first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
2823                 _DEBUG_TRACE("child_name = %s", first_child_name);
2824                 if (strcmp(first_child_name, ELEMENT_LAST) == 0) {
2825                         err = sync_agent_get_text_from_node(child, &lastAnchor);
2826                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2827                                 goto return_part;
2828                         }
2829                         child = child->next;
2830                         for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {
2831                         }
2832                 } else if (strcmp(first_child_name, ELEMENT_NEXT) == 0) {
2833                         err = sync_agent_get_text_from_node(child, &nextAnchor);
2834                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2835                                 goto return_part;
2836                         }
2837                         child = NULL;
2838                 }
2839
2840                 /* get second child : required nextAnchor */
2841                 if (child != NULL) {
2842                         const char *second_child_name = NULL;
2843                         second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
2844                         _DEBUG_TRACE("child_name = %s", second_child_name);
2845                         if (strcmp(second_child_name, ELEMENT_NEXT) == 0) {
2846                                 err = sync_agent_get_text_from_node(child, &nextAnchor);
2847                                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2848                                         goto return_part;
2849                                 }
2850                         } else {
2851                                 /* error */
2852                                 goto return_part;
2853                         }
2854                 }
2855
2856                 sa_error_type_e error = create_anchor(lastAnchor, nextAnchor, &anchor);
2857                 if (error != SA_INTERNAL_OK) {
2858                         _DEBUG_ERROR("create_anchor() failed !, error = %d", error);
2859                         goto return_part;
2860                 }
2861         }
2862
2863         _EXTERN_FUNC_EXIT;
2864         return anchor;
2865
2866  return_part:
2867
2868         _EXTERN_FUNC_EXIT;
2869         return NULL;
2870 }
2871
2872 static cred_s *__get_cred(WBXMLTreeNode * node)
2873 {
2874         _INNER_FUNC_ENTER;
2875
2876         retvm_if(node == NULL, NULL, "node is NULL");
2877
2878         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2879         cred_s *cred = NULL;
2880
2881         char *data = NULL;
2882         char *type = NULL;
2883         char *format = NULL;
2884
2885         WBXMLTreeNode *child = NULL;
2886
2887         for (child = node->children; child != NULL; child = child->next) {
2888                 if (child->type != WBXML_TREE_ELEMENT_NODE)
2889                         continue;
2890
2891                 const char *child_xml_name = NULL;
2892                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
2893
2894                 if (strcmp(child_xml_name, ELEMENT_META) == 0) {
2895                         WBXMLTreeNode *grand_child = child->children;
2896
2897                         const char *grand_child_xml_name = NULL;
2898                         grand_child_xml_name = (const char *)wbxml_tag_get_xml_name(grand_child->name);
2899
2900                         if (strcmp(grand_child_xml_name, ELEMENT_TYPE) == 0) {
2901                                 err = sync_agent_get_text_from_node(grand_child, &type);
2902                                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2903                                         goto return_part;
2904                                 }
2905                                 _DEBUG_VERBOSE("Type = [%s]", type);
2906                         } else if (strcmp(grand_child_xml_name, ELEMENT_FORMAT) == 0) {
2907                                 err = sync_agent_get_text_from_node(grand_child, &format);
2908                                 if (err != SYNC_AGENT_PB_RETURN_OK) {
2909                                         goto return_part;
2910                                 }
2911                                 _DEBUG_VERBOSE("Type = [%s]", format);
2912                         }
2913                 } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
2914                         err = sync_agent_get_text_from_node(child, &data);
2915                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2916                                 goto return_part;
2917                         }
2918                         _DEBUG_VERBOSE("Data = [%s]", data);
2919                 }
2920
2921         }
2922
2923         cred = create_cred_with_data(convert_auth_type(type), data);
2924
2925         format_type_e formatType = FORMAT_TYPE_UNKNOWN;
2926         if (format != NULL) {
2927                 if (strcmp(format, ELEMENT_B64) == 0)
2928                         formatType = FORMAT_TYPE_BASE64;
2929         }
2930
2931         set_cred_format_type(cred, formatType);
2932
2933         _INNER_FUNC_EXIT;
2934         return cred;
2935
2936  return_part:
2937
2938         _INNER_FUNC_EXIT;
2939         return NULL;
2940 }
2941
2942 static chal_s *_get_chal(WBXMLTreeNode * node)
2943 {
2944         _INNER_FUNC_ENTER;
2945
2946         retvm_if(node == NULL, NULL, "node is NULL");
2947
2948         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
2949
2950         chal_s *pChal = (chal_s *) calloc(1, sizeof(chal_s));
2951         if (pChal == NULL) {
2952                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
2953                 _DEBUG_ERROR("pChal is null");
2954                 goto return_part;
2955         }
2956
2957         WBXMLTreeNode *chal_child = node->children;
2958
2959         WBXMLTreeNode *meta_child = NULL;
2960
2961         for (meta_child = chal_child->children; meta_child != NULL; meta_child = meta_child->next) {
2962                 if (meta_child->type != WBXML_TREE_ELEMENT_NODE)
2963                         continue;
2964
2965                 const char *meta_child_xml_name = NULL;
2966                 meta_child_xml_name = (const char *)wbxml_tag_get_xml_name(meta_child->name);
2967
2968                 if (strcmp(meta_child_xml_name, ELEMENT_TYPE) == 0) {
2969                         char *type = NULL;
2970                         err = sync_agent_get_text_from_node(meta_child, &type);
2971                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2972                                 goto return_part;
2973                         }
2974                         _DEBUG_TRACE("Type = [%s]", type);
2975
2976                         pChal->type = convert_auth_type(type);
2977                 } else if (strcmp(meta_child_xml_name, ELEMENT_FORMAT) == 0) {
2978                         char *format = NULL;
2979                         err = sync_agent_get_text_from_node(meta_child, &format);
2980                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2981                                 goto return_part;
2982                         }
2983                         _DEBUG_TRACE("Format = [%s]", format);
2984
2985                         pChal->format = convert_format_type(format);
2986                 } else if (strcmp(meta_child_xml_name, ELEMENT_NEXTNONCE) == 0) {
2987                         char *nextnonce = NULL;
2988                         unsigned int nonce_len = 0;
2989                         err = sync_agent_get_binary_from_node(meta_child, &nextnonce, &nonce_len);
2990                         if (err != SYNC_AGENT_PB_RETURN_OK) {
2991                                 goto return_part;
2992                         }
2993                         _DEBUG_TRACE("NextNonce = [%s]", nextnonce);
2994                         if (pChal->format == FORMAT_TYPE_BASE64) {
2995                                 if (nextnonce != NULL)
2996                                         pChal->nonce_b64 = strdup(nextnonce);
2997                         } else {
2998                                 pChal->nonce_plain = (char *)malloc(nonce_len + 1);
2999                                 if (pChal->nonce_plain == NULL) {
3000                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3001                                         goto return_part;
3002                                 }
3003                                 memcpy(pChal->nonce_plain, nextnonce, nonce_len);
3004                                 pChal->nonce_plain[nonce_len] = '\0';
3005                         }
3006
3007                         pChal->nonce_length = nonce_len;
3008                 }
3009         }
3010
3011         _EXTERN_FUNC_EXIT;
3012         return pChal;
3013
3014  return_part:
3015
3016         if (pChal != NULL)
3017                 free_chal(pChal);
3018
3019         _EXTERN_FUNC_EXIT;
3020         return NULL;
3021 }
3022
3023 static sync_agent_pb_error_e _oma_ds_binder_devinf_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
3024 {
3025         _INNER_FUNC_ENTER;
3026
3027         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
3028
3029         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
3030
3031         /* get data from dom tree */
3032         devinf_s *pDevInf = (devinf_s *) calloc(1, sizeof(devinf_s));
3033         if (pDevInf == NULL) {
3034                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3035                 _DEBUG_ERROR("pDevInf is null");
3036                 goto return_part;
3037         }
3038
3039         WBXMLTreeNode *child = NULL;
3040
3041         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
3042                 if (child->type != WBXML_TREE_ELEMENT_NODE)
3043                         continue;
3044
3045                 const char *child_xml_name = NULL;
3046                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
3047
3048                 if (strcmp(child_xml_name, ELEMENT_VERDTD) == 0) {
3049                         char *verdtd = NULL;
3050                         err = sync_agent_get_text_from_node(child, &verdtd);
3051                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3052                                 goto return_part;
3053                         }
3054                         _DEBUG_TRACE("VerDTD = [%s]", verdtd);
3055
3056                         pDevInf->version = __get_oma_ds_devInf_version(verdtd);
3057                 } else if (strcmp(child_xml_name, ELEMENT_MAN) == 0) {
3058                         char *man = NULL;
3059                         err = sync_agent_get_text_from_node(child, &man);
3060                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3061                                 goto return_part;
3062                         }
3063                         _DEBUG_TRACE("Man = [%s]", man);
3064                         if (man != NULL)
3065                                 pDevInf->manufacturer = strdup(man);
3066                 } else if (strcmp(child_xml_name, ELEMENT_MOD) == 0) {
3067                         char *mod = NULL;
3068                         err = sync_agent_get_text_from_node(child, &mod);
3069                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3070                                 goto return_part;
3071                         }
3072                         _DEBUG_TRACE("Mod = [%s]", mod);
3073                         if (mod != NULL)
3074                                 pDevInf->model = strdup(mod);
3075                 } else if (strcmp(child_xml_name, ELEMENT_OEM) == 0) {
3076                         char *oem = NULL;
3077                         err = sync_agent_get_text_from_node(child, &oem);
3078                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3079                                 goto return_part;
3080                         }
3081                         _DEBUG_TRACE("OEM = [%s]", oem);
3082                         if (oem != NULL)
3083                                 pDevInf->oem = strdup(oem);
3084                 } else if (strcmp(child_xml_name, ELEMENT_FWV) == 0) {
3085                         char *fwv = NULL;
3086                         err = sync_agent_get_text_from_node(child, &fwv);
3087                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3088                                 goto return_part;
3089                         }
3090                         _DEBUG_TRACE("FwV = [%s]", fwv);
3091                         if (fwv != NULL)
3092                                 pDevInf->firmware_version = strdup(fwv);
3093                 } else if (strcmp(child_xml_name, ELEMENT_SWV) == 0) {
3094                         char *swv = NULL;
3095                         err = sync_agent_get_text_from_node(child, &swv);
3096                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3097                                 goto return_part;
3098                         }
3099                         _DEBUG_TRACE("SwV = [%s]", swv);
3100                         if (swv != NULL)
3101                                 pDevInf->software_version = strdup(swv);
3102                 } else if (strcmp(child_xml_name, ELEMENT_HWV) == 0) {
3103                         char *hwv = NULL;
3104                         err = sync_agent_get_text_from_node(child, &hwv);
3105                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3106                                 goto return_part;
3107                         }
3108                         _DEBUG_TRACE("HwV = [%s]", hwv);
3109                         if (hwv != NULL)
3110                                 pDevInf->hardware_version = strdup(hwv);
3111                 } else if (strcmp(child_xml_name, ELEMENT_DEVID) == 0) {
3112                         char *devID = NULL;
3113                         err = sync_agent_get_text_from_node(child, &devID);
3114                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3115                                 goto return_part;
3116                         }
3117                         _DEBUG_TRACE("DevID = [%s]", devID);
3118                         if (devID != NULL)
3119                                 pDevInf->dev_id = strdup(devID);
3120                 } else if (strcmp(child_xml_name, ELEMENT_DEVTYP) == 0) {
3121                         char *devtyp = NULL;
3122                         err = sync_agent_get_text_from_node(child, &devtyp);
3123                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3124                                 goto return_part;
3125                         }
3126                         _DEBUG_TRACE("DevTyp = [%s]", devtyp);
3127
3128                         pDevInf->devtyp = __get_oma_ds_devInf_device_type(devtyp);
3129                 } else if (strcmp(child_xml_name, ELEMENT_UTC) == 0) {
3130                         _DEBUG_TRACE("UTC");
3131                         pDevInf->supports_utc = 1;
3132                 } else if (strcmp(child_xml_name, ELEMENT_SUPPORTLARGEOBJS) == 0) {
3133                         _DEBUG_TRACE("SupportLargeObjs");
3134                         pDevInf->supports_large_objs = 1;
3135                 } else if (strcmp(child_xml_name, ELEMENT_SUPPORTNUMBEROFCHANGES) == 0) {
3136                         _DEBUG_TRACE("SupportNumberOfChanges");
3137                         pDevInf->supports_number_of_changes = 1;
3138                 } else if (strcmp(child_xml_name, ELEMENT_DATASTORE) == 0) {
3139
3140                         devinf_datastore_s *pDevInfDataStore = (devinf_datastore_s *) calloc(1, sizeof(devinf_datastore_s));
3141                         if (pDevInfDataStore == NULL) {
3142                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3143                                 _DEBUG_ERROR("pDevInfDataStore is null");
3144                                 goto return_part;
3145                         }
3146
3147                         WBXMLTreeNode *datastore_child = NULL;
3148
3149                         for (datastore_child = child->children; datastore_child != NULL; datastore_child = datastore_child->next) {
3150                                 if (datastore_child->type != WBXML_TREE_ELEMENT_NODE)
3151                                         continue;
3152
3153                                 const char *datastore_child_xml_name = NULL;
3154                                 datastore_child_xml_name = (const char *)wbxml_tag_get_xml_name(datastore_child->name);
3155
3156                                 if (strcmp(datastore_child_xml_name, ELEMENT_SOURCEREF) == 0) {
3157                                         char *sourceref = NULL;
3158                                         err = sync_agent_get_text_from_node(datastore_child, &sourceref);
3159                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3160                                                 if (pDevInfDataStore != NULL)
3161                                                         free(pDevInfDataStore);
3162
3163                                                 goto return_part;
3164                                         }
3165                                         _DEBUG_TRACE("SourceRef = [%s]", sourceref);
3166                                         if (sourceref != NULL)
3167                                                 pDevInfDataStore->source_ref = strdup(sourceref);
3168                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
3169                                         char *displayname = NULL;
3170                                         err = sync_agent_get_text_from_node(datastore_child, &displayname);
3171                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3172                                                 if (pDevInfDataStore != NULL)
3173                                                         free(pDevInfDataStore);
3174
3175                                                 goto return_part;
3176                                         }
3177                                         _DEBUG_TRACE("DisplayName = [%s]", displayname);
3178                                         if (displayname != NULL)
3179                                                 pDevInfDataStore->display_name = strdup(displayname);
3180                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_MAXGUIDSIZE) == 0) {
3181                                         char *maxguidsize = NULL;
3182                                         err = sync_agent_get_text_from_node(datastore_child, &maxguidsize);
3183                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3184                                                 if (pDevInfDataStore != NULL)
3185                                                         free(pDevInfDataStore);
3186
3187                                                 goto return_part;
3188                                         }
3189                                         _DEBUG_TRACE("MaxGUIDSize = [%s]", maxguidsize);
3190                                         if (maxguidsize != NULL)
3191                                                 pDevInfDataStore->max_guid_size = atoi(maxguidsize);
3192                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_RX_PREF) == 0) {
3193                                         devinf_content_type_s *devinf_content_type = __get_devinf_contenttype(datastore_child);
3194                                         if (devinf_content_type == NULL) {
3195                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3196                                                 if (pDevInfDataStore != NULL)
3197                                                         free(pDevInfDataStore);
3198
3199                                                 goto return_part;
3200                                         }
3201                                         pDevInfDataStore->rx_pref = devinf_content_type;
3202                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_RX) == 0) {
3203                                         devinf_content_type_s *devinf_content_type = __get_devinf_contenttype(datastore_child);
3204                                         if (devinf_content_type == NULL) {
3205                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3206                                                 if (pDevInfDataStore != NULL)
3207                                                         free(pDevInfDataStore);
3208
3209                                                 goto return_part;
3210                                         }
3211                                         pDevInfDataStore->rx = g_list_append(pDevInfDataStore->rx, devinf_content_type);
3212                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_TX_PREF) == 0) {
3213                                         devinf_content_type_s *devinf_content_type = __get_devinf_contenttype(datastore_child);
3214                                         if (devinf_content_type == NULL) {
3215                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3216                                                 if (pDevInfDataStore != NULL)
3217                                                         free(pDevInfDataStore);
3218
3219                                                 goto return_part;
3220                                         }
3221                                         pDevInfDataStore->tx_pref = devinf_content_type;
3222                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_TX) == 0) {
3223                                         devinf_content_type_s *devinf_content_type = __get_devinf_contenttype(datastore_child);
3224                                         if (devinf_content_type == NULL) {
3225                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3226                                                 if (pDevInfDataStore != NULL)
3227                                                         free(pDevInfDataStore);
3228
3229                                                 goto return_part;
3230                                         }
3231                                         pDevInfDataStore->tx = g_list_append(pDevInfDataStore->tx, devinf_content_type);
3232                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_CTCAP) == 0) {
3233
3234                                         devinf_ct_cap_s *pDevInfCtCap = (devinf_ct_cap_s *) calloc(1, sizeof(devinf_ct_cap_s));
3235                                         if (pDevInfCtCap == NULL) {
3236                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3237                                                 _DEBUG_ERROR("pDevInfCtCap is null");
3238                                                 if (pDevInfDataStore != NULL)
3239                                                         free(pDevInfDataStore);
3240
3241                                                 goto return_part;
3242                                         }
3243
3244                                         devinf_content_type_s *devinf_content_type = NULL;
3245                                         WBXMLTreeNode *ctcap_child = NULL;
3246
3247                                         for (ctcap_child = datastore_child->children; ctcap_child != NULL; ctcap_child = ctcap_child->next) {
3248                                                 if (ctcap_child->type != WBXML_TREE_ELEMENT_NODE)
3249                                                         continue;
3250
3251                                                 const char *ctcap_child_xml_name = NULL;
3252                                                 ctcap_child_xml_name = (const char *)wbxml_tag_get_xml_name(ctcap_child->name);
3253
3254                                                 if (strcmp(ctcap_child_xml_name, ELEMENT_CTTYPE) == 0) {
3255                                                         if (devinf_content_type == NULL) {
3256                                                                 devinf_content_type = (devinf_content_type_s *) calloc(1, sizeof(devinf_content_type_s));
3257                                                                 if (devinf_content_type == NULL) {
3258                                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3259                                                                         _DEBUG_ERROR("devinf_content_type is null");
3260                                                                         if (pDevInfDataStore != NULL)
3261                                                                                 free(pDevInfDataStore);
3262
3263                                                                         if (pDevInfCtCap != NULL)
3264                                                                                 free(pDevInfCtCap);
3265
3266                                                                         goto return_part;
3267                                                                 }
3268                                                         }
3269
3270                                                         char *cttype = NULL;
3271                                                         err = sync_agent_get_text_from_node(ctcap_child, &cttype);
3272                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3273                                                                 if (pDevInfDataStore != NULL)
3274                                                                         free(pDevInfDataStore);
3275
3276                                                                 if (pDevInfCtCap != NULL)
3277                                                                         free(pDevInfCtCap);
3278
3279                                                                 if (devinf_content_type != NULL)
3280                                                                         free(devinf_content_type);
3281
3282                                                                 goto return_part;
3283                                                         }
3284                                                         _DEBUG_TRACE("CTType = [%s]", cttype);
3285                                                         if (cttype != NULL)
3286                                                                 devinf_content_type->ct_type = strdup(cttype);
3287                                                 } else if (strcmp(ctcap_child_xml_name, ELEMENT_VERCT) == 0) {
3288                                                         if (devinf_content_type == NULL) {
3289                                                                 devinf_content_type = (devinf_content_type_s *) calloc(1, sizeof(devinf_content_type_s));
3290                                                                 if (devinf_content_type == NULL) {
3291                                                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3292                                                                         _DEBUG_ERROR("devinf_content_type is null");
3293
3294                                                                         if (pDevInfDataStore != NULL)
3295                                                                                 free(pDevInfDataStore);
3296
3297                                                                         if (pDevInfCtCap != NULL)
3298                                                                                 free(pDevInfCtCap);
3299
3300                                                                         if (devinf_content_type != NULL)
3301                                                                                 free(devinf_content_type);
3302
3303                                                                         goto return_part;
3304                                                                 }
3305                                                         }
3306
3307                                                         char *verct = NULL;
3308                                                         err = sync_agent_get_text_from_node(ctcap_child, &verct);
3309                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3310
3311                                                                 if (pDevInfDataStore != NULL)
3312                                                                         free(pDevInfDataStore);
3313
3314                                                                 if (pDevInfCtCap != NULL)
3315                                                                         free(pDevInfCtCap);
3316
3317                                                                 if (devinf_content_type != NULL)
3318                                                                         free(devinf_content_type);
3319
3320                                                                 goto return_part;
3321                                                         }
3322                                                         _DEBUG_TRACE("VerCT = [%s]", verct);
3323                                                         if (verct != NULL)
3324                                                                 devinf_content_type->verct = strdup(verct);
3325                                                 } else if (strcmp(ctcap_child_xml_name, ELEMENT_FIELDLEVEL) == 0) {
3326                                                         /*TODO fieldlevel */
3327
3328                                                 } else if (strcmp(ctcap_child_xml_name, ELEMENT_PROPERTY) == 0) {
3329
3330                                                         devinf_property_s *pDevInfProperty = (devinf_property_s *) calloc(1, sizeof(devinf_property_s));
3331                                                         if (pDevInfProperty == NULL) {
3332                                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3333                                                                 _DEBUG_ERROR("pDevInfProperty is null");
3334
3335                                                                 if (pDevInfDataStore != NULL)
3336                                                                         free(pDevInfDataStore);
3337
3338                                                                 if (pDevInfCtCap != NULL)
3339                                                                         free(pDevInfCtCap);
3340
3341                                                                 if (devinf_content_type != NULL)
3342                                                                         free(devinf_content_type);
3343
3344                                                                 goto return_part;
3345                                                         }
3346
3347                                                         WBXMLTreeNode *property_child = NULL;
3348                                                         for (property_child = ctcap_child->children; property_child != NULL; property_child = property_child->next) {
3349                                                                 if (property_child->type != WBXML_TREE_ELEMENT_NODE)
3350                                                                         continue;
3351
3352                                                                 const char *property_child_xml_name = NULL;
3353                                                                 property_child_xml_name = (const char *)wbxml_tag_get_xml_name(property_child->name);
3354
3355                                                                 if (strcmp(property_child_xml_name, ELEMENT_PROPNAME) == 0) {
3356                                                                         char *propname = NULL;
3357                                                                         err = sync_agent_get_text_from_node(property_child, &propname);
3358                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3359
3360                                                                                 if (pDevInfDataStore != NULL)
3361                                                                                         free(pDevInfDataStore);
3362
3363                                                                                 if (pDevInfCtCap != NULL)
3364                                                                                         free(pDevInfCtCap);
3365
3366                                                                                 if (devinf_content_type != NULL)
3367                                                                                         free(devinf_content_type);
3368
3369                                                                                 if (pDevInfProperty != NULL)
3370                                                                                         free(pDevInfProperty);
3371
3372                                                                                 goto return_part;
3373                                                                         }
3374                                                                         _DEBUG_TRACE("PropName = [%s]", propname);
3375                                                                         if (propname != NULL)
3376                                                                                 pDevInfProperty->prop_name = strdup(propname);
3377                                                                 } else if (strcmp(property_child_xml_name, ELEMENT_DATATYPE) == 0) {
3378                                                                         char *datatype = NULL;
3379                                                                         err = sync_agent_get_text_from_node(property_child, &datatype);
3380                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3381
3382                                                                                 if (pDevInfDataStore != NULL)
3383                                                                                         free(pDevInfDataStore);
3384
3385                                                                                 if (pDevInfCtCap != NULL)
3386                                                                                         free(pDevInfCtCap);
3387
3388                                                                                 if (devinf_content_type != NULL)
3389                                                                                         free(devinf_content_type);
3390
3391                                                                                 if (pDevInfProperty != NULL)
3392                                                                                         free(pDevInfProperty);
3393
3394                                                                                 goto return_part;
3395                                                                         }
3396                                                                         _DEBUG_TRACE("DataType = [%s]", datatype);
3397                                                                         if (datatype != NULL)
3398                                                                                 pDevInfProperty->data_type = strdup(datatype);
3399                                                                 } else if (strcmp(property_child_xml_name, ELEMENT_MAXOCCUR) == 0) {
3400                                                                         char *maxoccur = NULL;
3401                                                                         err = sync_agent_get_text_from_node(property_child, &maxoccur);
3402                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3403
3404                                                                                 if (pDevInfDataStore != NULL)
3405                                                                                         free(pDevInfDataStore);
3406
3407                                                                                 if (pDevInfCtCap != NULL)
3408                                                                                         free(pDevInfCtCap);
3409
3410                                                                                 if (devinf_content_type != NULL)
3411                                                                                         free(devinf_content_type);
3412
3413                                                                                 if (pDevInfProperty != NULL)
3414                                                                                         free(pDevInfProperty);
3415
3416                                                                                 goto return_part;
3417                                                                         }
3418                                                                         _DEBUG_TRACE("MaxOccur = [%s]", maxoccur);
3419                                                                         if (maxoccur != NULL)
3420                                                                                 pDevInfProperty->max_occur = atoi(maxoccur);
3421                                                                 } else if (strcmp(property_child_xml_name, ELEMENT_MAXSIZE) == 0) {
3422                                                                         char *maxsize = NULL;
3423                                                                         err = sync_agent_get_text_from_node(property_child, &maxsize);
3424                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3425
3426                                                                                 if (pDevInfDataStore != NULL)
3427                                                                                         free(pDevInfDataStore);
3428
3429                                                                                 if (pDevInfCtCap != NULL)
3430                                                                                         free(pDevInfCtCap);
3431
3432                                                                                 if (devinf_content_type != NULL)
3433                                                                                         free(devinf_content_type);
3434
3435                                                                                 if (pDevInfProperty != NULL)
3436                                                                                         free(pDevInfProperty);
3437
3438                                                                                 goto return_part;
3439                                                                         }
3440                                                                         _DEBUG_TRACE("MaxSize = [%s]", maxsize);
3441                                                                         if (maxsize != NULL)
3442                                                                                 pDevInfProperty->max_size = atoi(maxsize);
3443                                                                 } else if (strcmp(property_child_xml_name, ELEMENT_NOTRUNCATE) == 0) {
3444                                                                         _DEBUG_TRACE("NoTruncate");
3445                                                                         pDevInfProperty->no_truncate = 1;
3446                                                                 } else if (strcmp(property_child_xml_name, ELEMENT_VALENUM) == 0) {
3447                                                                         char *valenum = NULL;
3448                                                                         err = sync_agent_get_text_from_node(property_child, &valenum);
3449                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3450
3451                                                                                 if (pDevInfDataStore != NULL)
3452                                                                                         free(pDevInfDataStore);
3453
3454                                                                                 if (pDevInfCtCap != NULL)
3455                                                                                         free(pDevInfCtCap);
3456
3457                                                                                 if (devinf_content_type != NULL)
3458                                                                                         free(devinf_content_type);
3459
3460                                                                                 if (pDevInfProperty != NULL)
3461                                                                                         free(pDevInfProperty);
3462
3463                                                                                 goto return_part;
3464                                                                         }
3465                                                                         _DEBUG_TRACE("ValEnum = [%s]", valenum);
3466                                                                         if (valenum != NULL)
3467                                                                                 pDevInfProperty->val_enums = g_list_append(pDevInfProperty->val_enums, strdup(valenum));
3468                                                                 } else if (strcmp(property_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
3469                                                                         char *displayname = NULL;
3470                                                                         err = sync_agent_get_text_from_node(property_child, &displayname);
3471                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3472
3473                                                                                 if (pDevInfDataStore != NULL)
3474                                                                                         free(pDevInfDataStore);
3475
3476                                                                                 if (pDevInfCtCap != NULL)
3477                                                                                         free(pDevInfCtCap);
3478
3479                                                                                 if (devinf_content_type != NULL)
3480                                                                                         free(devinf_content_type);
3481
3482                                                                                 if (pDevInfProperty != NULL)
3483                                                                                         free(pDevInfProperty);
3484
3485                                                                                 goto return_part;
3486                                                                         }
3487                                                                         _DEBUG_TRACE("DisplayName = [%s]", displayname);
3488                                                                         if (displayname != NULL)
3489                                                                                 pDevInfProperty->display_name = strdup(displayname);
3490                                                                 } else if (strcmp(property_child_xml_name, ELEMENT_PROPPARAM) == 0) {
3491
3492                                                                         devinf_prop_param_s *pDevInfPropParam = (devinf_prop_param_s *) calloc(1, sizeof(devinf_prop_param_s));
3493                                                                         if (pDevInfPropParam == NULL) {
3494                                                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3495                                                                                 _DEBUG_ERROR("pDevInfPropParam is null");
3496
3497                                                                                 if (pDevInfDataStore != NULL)
3498                                                                                         free(pDevInfDataStore);
3499
3500                                                                                 if (pDevInfCtCap != NULL)
3501                                                                                         free(pDevInfCtCap);
3502
3503                                                                                 if (devinf_content_type != NULL)
3504                                                                                         free(devinf_content_type);
3505
3506                                                                                 if (pDevInfProperty != NULL)
3507                                                                                         free(pDevInfProperty);
3508
3509                                                                                 goto return_part;
3510                                                                         }
3511
3512                                                                         WBXMLTreeNode *propparam_child = NULL;
3513
3514                                                                         for (propparam_child = property_child->children; propparam_child != NULL; propparam_child = propparam_child->next) {
3515                                                                                 if (propparam_child->type != WBXML_TREE_ELEMENT_NODE)
3516                                                                                         continue;
3517
3518                                                                                 const char *propparam_child_xml_name = NULL;
3519                                                                                 propparam_child_xml_name = (const char *)wbxml_tag_get_xml_name(propparam_child->name);
3520
3521                                                                                 if (strcmp(propparam_child_xml_name, ELEMENT_PARAMNAME) == 0) {
3522                                                                                         char *paramname = NULL;
3523                                                                                         err = sync_agent_get_text_from_node(propparam_child, &paramname);
3524                                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3525
3526                                                                                                 if (pDevInfDataStore != NULL)
3527                                                                                                         free(pDevInfDataStore);
3528
3529                                                                                                 if (pDevInfCtCap != NULL)
3530                                                                                                         free(pDevInfCtCap);
3531
3532                                                                                                 if (devinf_content_type != NULL)
3533                                                                                                         free(devinf_content_type);
3534
3535                                                                                                 if (pDevInfProperty != NULL)
3536                                                                                                         free(pDevInfProperty);
3537
3538                                                                                                 goto return_part;
3539                                                                                         }
3540                                                                                         _DEBUG_TRACE("ParamName = [%s]", paramname);
3541                                                                                         if (paramname != NULL)
3542                                                                                                 pDevInfPropParam->param_name = strdup(paramname);
3543                                                                                 } else if (strcmp(propparam_child_xml_name, ELEMENT_DATATYPE) == 0) {
3544                                                                                         char *datatype = NULL;
3545                                                                                         err = sync_agent_get_text_from_node(propparam_child, &datatype);
3546                                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3547
3548                                                                                                 if (pDevInfDataStore != NULL)
3549                                                                                                         free(pDevInfDataStore);
3550
3551                                                                                                 if (pDevInfCtCap != NULL)
3552                                                                                                         free(pDevInfCtCap);
3553
3554                                                                                                 if (devinf_content_type != NULL)
3555                                                                                                         free(devinf_content_type);
3556
3557                                                                                                 if (pDevInfProperty != NULL)
3558                                                                                                         free(pDevInfProperty);
3559
3560                                                                                                 goto return_part;
3561                                                                                         }
3562                                                                                         _DEBUG_TRACE("DataType = [%s]", datatype);
3563                                                                                         if (datatype != NULL)
3564                                                                                                 pDevInfPropParam->data_type = strdup(datatype);
3565                                                                                 } else if (strcmp(propparam_child_xml_name, ELEMENT_VALENUM) == 0) {
3566                                                                                         char *valenum = NULL;
3567                                                                                         err = sync_agent_get_text_from_node(propparam_child, &valenum);
3568                                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3569
3570                                                                                                 if (pDevInfDataStore != NULL)
3571                                                                                                         free(pDevInfDataStore);
3572
3573                                                                                                 if (pDevInfCtCap != NULL)
3574                                                                                                         free(pDevInfCtCap);
3575
3576                                                                                                 if (devinf_content_type != NULL)
3577                                                                                                         free(devinf_content_type);
3578
3579                                                                                                 if (pDevInfProperty != NULL)
3580                                                                                                         free(pDevInfProperty);
3581
3582                                                                                                 goto return_part;
3583                                                                                         }
3584                                                                                         _DEBUG_TRACE("ValEnum = [%s]", valenum);
3585                                                                                         if (valenum != NULL)
3586                                                                                                 pDevInfPropParam->val_enums = g_list_append(pDevInfPropParam->val_enums, strdup(valenum));
3587                                                                                 } else if (strcmp(propparam_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
3588                                                                                         char *displayname = NULL;
3589                                                                                         err = sync_agent_get_text_from_node(propparam_child, &displayname);
3590                                                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3591
3592                                                                                                 if (pDevInfDataStore != NULL)
3593                                                                                                         free(pDevInfDataStore);
3594
3595                                                                                                 if (pDevInfCtCap != NULL)
3596                                                                                                         free(pDevInfCtCap);
3597
3598                                                                                                 if (devinf_content_type != NULL)
3599                                                                                                         free(devinf_content_type);
3600
3601                                                                                                 if (pDevInfProperty != NULL)
3602                                                                                                         free(pDevInfProperty);
3603
3604                                                                                                 goto return_part;
3605                                                                                         }
3606                                                                                         _DEBUG_TRACE("DisplayName = [%s]", displayname);
3607                                                                                         if (displayname != NULL)
3608                                                                                                 pDevInfPropParam->display_name = strdup(displayname);
3609                                                                                 }
3610                                                                         }
3611
3612                                                                         pDevInfProperty->prop_params = g_list_append(pDevInfProperty->prop_params, pDevInfPropParam);
3613                                                                 }
3614                                                         }
3615
3616                                                         pDevInfCtCap->properties = g_list_append(pDevInfCtCap->properties, pDevInfProperty);
3617                                                 }
3618                                         }
3619                                         pDevInfCtCap->ct = devinf_content_type;
3620                                         pDevInfDataStore->ct_caps = g_list_append(pDevInfDataStore->ct_caps, pDevInfCtCap);
3621                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_DSMEM) == 0) {
3622
3623                                         /*TODO DSMem */
3624                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_SUPPORTHIERARCHICALSYNC) == 0) {
3625                                         _DEBUG_TRACE("SupportHierarchicalSync");
3626                                         pDevInfDataStore->supports_hierarchical_sync = 1;
3627                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_SYNCCAP) == 0) {
3628
3629                                         WBXMLTreeNode *synccap_child = NULL;
3630
3631                                         for (synccap_child = datastore_child->children; synccap_child != NULL; synccap_child = synccap_child->next) {
3632                                                 if (synccap_child->type != WBXML_TREE_ELEMENT_NODE)
3633                                                         continue;
3634
3635                                                 const char *synccap_child_xml_name = NULL;
3636                                                 synccap_child_xml_name = (const char *)wbxml_tag_get_xml_name(synccap_child->name);
3637
3638                                                 if (strcmp(synccap_child_xml_name, ELEMENT_SYNCTYPE) == 0) {
3639                                                         char *synctype_str = NULL;
3640                                                         unsigned int synctype = 0;
3641                                                         err = sync_agent_get_text_from_node(synccap_child, &synctype_str);
3642                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3643
3644                                                                 if (pDevInfDataStore != NULL)
3645                                                                         free(pDevInfDataStore);
3646
3647                                                                 goto return_part;
3648                                                         }
3649                                                         _DEBUG_TRACE("SyncType = [%s]", synctype_str);
3650                                                         if (synctype_str != NULL) {
3651                                                                 synctype = atoi(synctype_str);
3652                                                                 synctype = 1 << (synctype - 1);
3653                                                         }
3654                                                         /*DevInfSyncCap synccap = convert_devinf_synccap(synctype); */
3655                                                         set_devinf_datastore_sync_cap(pDevInfDataStore, synctype, 1);
3656                                                 }
3657                                         }
3658                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_FILTER_RX) == 0) {
3659                                         /*TODO filter-rx */
3660                                 } else if (strcmp(datastore_child_xml_name, ELEMENT_FILTERCAP) == 0) {
3661                                         /*TODO filtercap */
3662                                 }
3663                         }
3664                         pDevInf->datastores = g_list_append(pDevInf->datastores, pDevInfDataStore);
3665                 }
3666         }
3667
3668  return_part:
3669         if (err == SYNC_AGENT_PB_RETURN_OK) {
3670                 *content = pDevInf;
3671         } else {
3672                 _DEBUG_ERROR("error");
3673                 free_devinf(pDevInf);
3674         }
3675
3676         _EXTERN_FUNC_EXIT;
3677         return err;
3678 }
3679
3680 static sync_agent_pb_error_e _oma_ds_binder_header_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
3681 {
3682         _INNER_FUNC_ENTER;
3683
3684         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
3685
3686         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
3687
3688         /* get data from dom tree */
3689         sync_hdr_s *pSyncHdr = (sync_hdr_s *) calloc(1, sizeof(sync_hdr_s));
3690         if (pSyncHdr == NULL) {
3691                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3692                 _DEBUG_ERROR("pSyncHdr is null");
3693                 goto return_part;
3694         }
3695
3696         WBXMLTreeNode *child = NULL;
3697
3698         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
3699                 if (child->type != WBXML_TREE_ELEMENT_NODE)
3700                         continue;
3701
3702                 const char *child_xml_name = NULL;
3703                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
3704
3705                 if (strcmp(child_xml_name, ELEMENT_VERDTD) == 0) {
3706                         char *verdtd = NULL;
3707                         err = sync_agent_get_text_from_node(child, &verdtd);
3708                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3709                                 goto return_part;
3710                         }
3711                         _DEBUG_TRACE("VerDTD = [%s]", verdtd);
3712
3713                         pSyncHdr->version = __get_oma_ds_protocol_version(verdtd);
3714                 } else if (strcmp(child_xml_name, ELEMENT_SESSIONID) == 0) {
3715                         char *sessionID = NULL;
3716                         err = sync_agent_get_text_from_node(child, &sessionID);
3717                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3718                                 goto return_part;
3719                         }
3720                         _DEBUG_TRACE("SessionID = [%s]", sessionID);
3721
3722                         if (sessionID != NULL)
3723                                 pSyncHdr->session_id = strdup(sessionID);
3724                         else
3725                                 pSyncHdr->session_id = NULL;
3726                 } else if (strcmp(child_xml_name, ELEMENT_MSGID) == 0) {
3727                         char *msgID = NULL;
3728                         err = sync_agent_get_text_from_node(child, &msgID);
3729                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3730                                 goto return_part;
3731                         }
3732                         _DEBUG_TRACE("MsgID = [%s]", msgID);
3733                         if (msgID != NULL)
3734                                 pSyncHdr->message_id = atoi(msgID);
3735                 } else if (strcmp(child_xml_name, ELEMENT_TARGET) == 0) {
3736                         location_s *pTargetLocation = _get_location(child);
3737                         if (pTargetLocation == NULL) {
3738                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3739                                 goto return_part;
3740                         }
3741                         pSyncHdr->target = pTargetLocation;
3742                 } else if (strcmp(child_xml_name, ELEMENT_SOURCE) == 0) {
3743                         location_s *pSourceLocation = _get_location(child);
3744                         if (pSourceLocation == NULL) {
3745                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3746                                 goto return_part;
3747                         }
3748                         pSyncHdr->source = pSourceLocation;
3749                 } else if (strcmp(child_xml_name, ELEMENT_RESPURI) == 0) {
3750                         char *resp_uri = NULL;
3751                         err = sync_agent_get_text_from_node(child, &resp_uri);
3752                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3753                                 goto return_part;
3754                         }
3755                         _DEBUG_TRACE("resp_uri = [%s]", resp_uri);
3756                         if (resp_uri != NULL)
3757                                 pSyncHdr->response_uri = strdup(resp_uri);
3758                 } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
3759                         _DEBUG_TRACE("noResp\n");
3760                         pSyncHdr->no_response = 1;
3761                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
3762                         _DEBUG_TRACE("Cred\n");
3763                         cred_s *cred = NULL;
3764                         cred = __get_cred(child);
3765                         if (cred == NULL) {
3766                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3767                                 goto return_part;
3768                         }
3769                         pSyncHdr->cred = cred;
3770                 } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
3771
3772                 }
3773         }
3774
3775  return_part:
3776         if (err == SYNC_AGENT_PB_RETURN_OK) {
3777                 *content = pSyncHdr;
3778         } else {
3779                 _DEBUG_ERROR("error");
3780                 free_sync_hdr(pSyncHdr);
3781         }
3782
3783         _EXTERN_FUNC_EXIT;
3784         return err;
3785 }
3786
3787 static sync_agent_pb_error_e _oma_ds_binder_results_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
3788 {
3789         _INNER_FUNC_ENTER;
3790
3791         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
3792         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
3793
3794         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
3795         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
3796
3797         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
3798
3799         /* get data from dom tree */
3800         command_s *pResults = (command_s *) calloc(1, sizeof(command_s));
3801         if (pResults == NULL) {
3802                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3803                 _DEBUG_ERROR("pResults is null");
3804                 goto return_part;
3805         }
3806
3807         pResults->type = COMMAND_TYPE_RESULTS;
3808         pResults->msg_id = pSyncHdr->message_id;
3809         pResults->ref_count = 1;
3810
3811         WBXMLTreeNode *child = NULL;
3812
3813         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
3814                 if (child->type != WBXML_TREE_ELEMENT_NODE)
3815                         continue;
3816
3817                 const char *child_xml_name = NULL;
3818                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
3819
3820                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
3821                         char *cmd_id = NULL;
3822                         err = sync_agent_get_text_from_node(child, &cmd_id);
3823                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3824                                 goto return_part;
3825                         }
3826                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
3827                         if (cmd_id != NULL)
3828                                 pResults->cmd_id = atoi(cmd_id);
3829                 } else if (strcmp(child_xml_name, ELEMENT_MSGREF) == 0) {
3830                         char *msg_ref = NULL;
3831                         err = sync_agent_get_text_from_node(child, &msg_ref);
3832                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3833                                 goto return_part;
3834                         }
3835                         _DEBUG_TRACE("MsgRef = [%s]", msg_ref);
3836                         if (msg_ref != NULL)
3837                                 pResults->private.results.msg_ref = atoi(msg_ref);
3838                 } else if (strcmp(child_xml_name, ELEMENT_CMDREF) == 0) {
3839                         char *cmd_ref = NULL;
3840                         err = sync_agent_get_text_from_node(child, &cmd_ref);
3841                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3842                                 goto return_part;
3843                         }
3844                         _DEBUG_TRACE("MsgRef = [%s]", cmd_ref);
3845                         if (cmd_ref != NULL)
3846                                 pResults->private.results.cmd_ref = atoi(cmd_ref);
3847                 } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
3848
3849                         WBXMLTreeNode *grandchild = NULL;
3850
3851                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
3852                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
3853                                         continue;
3854
3855                                 const char *grandchild_xml_name = NULL;
3856                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
3857
3858                                 if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
3859                                         char *contentType = NULL;
3860                                         err = sync_agent_get_text_from_node(grandchild, &contentType);
3861                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3862                                                 goto return_part;
3863                                         }
3864                                         _DEBUG_TRACE("Content Type = [%s]", contentType);
3865                                         if (contentType != NULL)
3866                                                 pResults->private.results.type = strdup(contentType);
3867                                 }
3868                         }
3869                 } else if (strcmp(child_xml_name, ELEMENT_TARGETREF) == 0) {
3870                         /*TODO targetRef */
3871                 } else if (strcmp(child_xml_name, ELEMENT_SOURCEREF) == 0) {
3872                         /*TODO sourceRef */
3873                 } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
3874                         /*create item in results command */
3875                         item_s *item = create_item();
3876                         if (item == NULL) {
3877                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3878                                 goto return_part;
3879                         }
3880                         pResults->private.results.item = item;
3881
3882                         WBXMLTreeNode *grandchild = NULL;
3883
3884                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
3885                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
3886                                         continue;
3887
3888                                 const char *grandchild_xml_name = NULL;
3889                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
3890
3891                                 if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
3892                                         location_s *pSourceLocation = _get_location(grandchild);
3893                                         if (pSourceLocation == NULL) {
3894                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3895                                                 goto return_part;
3896                                         }
3897                                         pResults->private.results.item->source = pSourceLocation;
3898                                 } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
3899                                         location_s *pTargetLocation = _get_location(grandchild);
3900                                         if (pTargetLocation == NULL) {
3901                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3902                                                 goto return_part;
3903                                         }
3904                                         pResults->private.results.item->target = pTargetLocation;
3905                                 } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
3906                                         /* TODO data */
3907                                 }
3908                         }
3909                 }
3910         }
3911  return_part:
3912         if (err == SYNC_AGENT_PB_RETURN_OK) {
3913                 *content = pResults;
3914         } else {
3915                 _DEBUG_ERROR("error");
3916                 free_command(pResults);
3917         }
3918
3919         _EXTERN_FUNC_EXIT;
3920         return err;
3921 }
3922
3923 static sync_agent_pb_error_e _oma_ds_binder_put_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
3924 {
3925         _INNER_FUNC_ENTER;
3926
3927         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
3928         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
3929
3930         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
3931         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
3932
3933         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
3934
3935         /* get data from dom tree */
3936         command_s *pPut = (command_s *) calloc(1, sizeof(command_s));
3937         if (pPut == NULL) {
3938                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3939                 _DEBUG_ERROR("pPut is null");
3940                 goto return_part;
3941         }
3942
3943         pPut->type = COMMAND_TYPE_PUT;
3944         pPut->msg_id = pSyncHdr->message_id;
3945         pPut->ref_count = 1;
3946
3947         WBXMLTreeNode *child = NULL;
3948
3949         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
3950                 if (child->type != WBXML_TREE_ELEMENT_NODE)
3951                         continue;
3952
3953                 const char *child_xml_name = NULL;
3954                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
3955
3956                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
3957                         char *cmd_id = NULL;
3958                         err = sync_agent_get_text_from_node(child, &cmd_id);
3959                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3960                                 goto return_part;
3961                         }
3962                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
3963                         if (cmd_id != NULL)
3964                                 pPut->cmd_id = atoi(cmd_id);
3965                 } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
3966                         _DEBUG_TRACE("NoResp");
3967                         pPut->no_resp = 1;
3968                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
3969                         _DEBUG_TRACE("Cred\n");
3970                         cred_s *cred = NULL;
3971                         cred = __get_cred(child);
3972                         if (cred == NULL) {
3973                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
3974                                 goto return_part;
3975                         }
3976                         pPut->cred = cred;
3977                 } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
3978                         WBXMLTreeNode *grandchild = NULL;
3979
3980                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
3981                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
3982                                         continue;
3983
3984                                 const char *grandchild_xml_name = NULL;
3985                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
3986
3987                                 if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
3988                                         char *contentType = NULL;
3989                                         err = sync_agent_get_text_from_node(grandchild, &contentType);
3990                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
3991                                                 goto return_part;
3992                                         }
3993                                         _DEBUG_TRACE("Content Type = [%s]", contentType);
3994                                         if (contentType != NULL)
3995                                                 pPut->private.access.type = strdup(contentType);
3996                                 }
3997                         }
3998                 } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
3999                         /*create item in put command */
4000                         item_s *item = create_item();
4001                         if (item == NULL) {
4002                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4003                                 goto return_part;
4004                         }
4005                         pPut->private.access.item = item;
4006
4007                         WBXMLTreeNode *grandchild = NULL;
4008
4009                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4010                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4011                                         continue;
4012
4013                                 const char *grandchild_xml_name = NULL;
4014                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4015
4016                                 if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
4017                                         location_s *pSourceLocation = _get_location(grandchild);
4018                                         if (pSourceLocation == NULL) {
4019                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4020                                                 goto return_part;
4021                                         }
4022                                         pPut->private.access.item->source = pSourceLocation;
4023                                 } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
4024                                         location_s *pTargetLocation = _get_location(grandchild);
4025                                         if (pTargetLocation == NULL) {
4026                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4027                                                 goto return_part;
4028                                         }
4029                                         pPut->private.access.item->target = pTargetLocation;
4030                                 } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
4031                                         /* TODO data */
4032                                 }
4033                         }
4034                 }
4035         }
4036
4037  return_part:
4038         if (err == SYNC_AGENT_PB_RETURN_OK) {
4039                 *content = pPut;
4040         } else {
4041                 _DEBUG_ERROR("error");
4042                 free_command(pPut);
4043         }
4044
4045         _EXTERN_FUNC_EXIT;
4046         return err;
4047 }
4048
4049 static sync_agent_pb_error_e _oma_ds_binder_get_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4050 {
4051         _INNER_FUNC_ENTER;
4052
4053         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
4054         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
4055
4056         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
4057         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
4058
4059         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4060
4061         /* get data from dom tree */
4062         command_s *pGet = (command_s *) calloc(1, sizeof(command_s));
4063         if (pGet == NULL) {
4064                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4065                 _DEBUG_ERROR("pGet is null");
4066                 goto return_part;
4067         }
4068
4069         pGet->type = COMMAND_TYPE_GET;
4070         pGet->msg_id = pSyncHdr->message_id;
4071         pGet->ref_count = 1;
4072
4073         WBXMLTreeNode *child = NULL;
4074
4075         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
4076                 if (child->type != WBXML_TREE_ELEMENT_NODE)
4077                         continue;
4078
4079                 const char *child_xml_name = NULL;
4080                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
4081
4082                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
4083                         char *cmd_id = NULL;
4084                         err = sync_agent_get_text_from_node(child, &cmd_id);
4085                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4086                                 goto return_part;
4087                         }
4088                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
4089                         if (cmd_id != NULL)
4090                                 pGet->cmd_id = atoi(cmd_id);
4091                 } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
4092                         _DEBUG_TRACE("NoResp");
4093                         pGet->no_resp = 1;
4094                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
4095                         _DEBUG_TRACE("Cred\n");
4096                         cred_s *cred = NULL;
4097                         cred = __get_cred(child);
4098                         if (cred == NULL) {
4099                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4100                                 goto return_part;
4101                         }
4102                         pGet->cred = cred;
4103                 } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
4104
4105                         WBXMLTreeNode *grandchild = NULL;
4106
4107                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4108                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4109                                         continue;
4110
4111                                 const char *grandchild_xml_name = NULL;
4112                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4113
4114                                 if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
4115                                         char *contentType = NULL;
4116                                         err = sync_agent_get_text_from_node(grandchild, &contentType);
4117                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4118                                                 goto return_part;
4119                                         }
4120                                         _DEBUG_TRACE("Content Type = [%s]", contentType);
4121                                         if (contentType != NULL)
4122                                                 pGet->private.access.type = strdup(contentType);
4123                                 }
4124                         }
4125                 } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
4126                         /*create item in put command */
4127                         item_s *item = create_item();
4128                         if (item == NULL) {
4129                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4130                                 goto return_part;
4131                         }
4132                         pGet->private.access.item = item;
4133
4134                         WBXMLTreeNode *grandchild = NULL;
4135                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4136                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4137                                         continue;
4138
4139                                 const char *grandchild_xml_name = NULL;
4140                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4141
4142                                 if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
4143                                         location_s *pSourceLocation = _get_location(grandchild);
4144                                         if (pSourceLocation == NULL) {
4145                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4146                                                 goto return_part;
4147                                         }
4148                                         pGet->private.access.item->source = pSourceLocation;
4149                                 } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
4150                                         location_s *pTargetLocation = _get_location(grandchild);
4151                                         if (pTargetLocation == NULL) {
4152                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4153                                                 goto return_part;
4154                                         }
4155                                         pGet->private.access.item->target = pTargetLocation;
4156                                 } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
4157                                         /* TODO data */
4158                                 }
4159                         }
4160                 }
4161         }
4162
4163  return_part:
4164         if (err == SYNC_AGENT_PB_RETURN_OK) {
4165                 *content = pGet;
4166         } else {
4167                 _DEBUG_ERROR("error");
4168                 free_command(pGet);
4169         }
4170
4171         _EXTERN_FUNC_EXIT;
4172         return err;
4173 }
4174
4175 static sync_agent_pb_error_e _oma_ds_binder_alert_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4176 {
4177         _INNER_FUNC_ENTER;
4178
4179         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
4180         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
4181
4182         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
4183         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
4184
4185         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4186
4187         /* get data from dom tree */
4188         command_s *pAlert = (command_s *) calloc(1, sizeof(command_s));
4189         if (pAlert == NULL) {
4190                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4191                 _DEBUG_ERROR("pAlert is null");
4192                 goto return_part;
4193         }
4194
4195         pAlert->type = COMMAND_TYPE_ALERT;
4196         pAlert->msg_id = pSyncHdr->message_id;
4197         pAlert->ref_count = 1;
4198
4199         WBXMLTreeNode *child = NULL;
4200
4201         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
4202                 if (child->type != WBXML_TREE_ELEMENT_NODE)
4203                         continue;
4204
4205                 const char *child_xml_name = NULL;
4206                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
4207
4208                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
4209                         char *cmd_id = NULL;
4210                         err = sync_agent_get_text_from_node(child, &cmd_id);
4211                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4212                                 goto return_part;
4213                         }
4214                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
4215                         if (cmd_id != NULL)
4216                                 pAlert->cmd_id = atoi(cmd_id);
4217                 } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
4218                         _DEBUG_TRACE("NoResp");
4219                         pAlert->no_resp = 1;
4220                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
4221                         _DEBUG_TRACE("Cred\n");
4222                         cred_s *cred = NULL;
4223                         cred = __get_cred(child);
4224                         if (cred == NULL) {
4225                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4226                                 goto return_part;
4227                         }
4228                         pAlert->cred = cred;
4229                 } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
4230                         char *data = NULL;
4231                         err = sync_agent_get_text_from_node(child, &data);
4232                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4233                                 goto return_part;
4234                         }
4235                         _DEBUG_TRACE("Data = [%s]", data);
4236                         if (data != NULL)
4237                                 pAlert->private.alert.type = atoi(data);
4238                 } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
4239                         WBXMLTreeNode *grandchild = NULL;
4240
4241                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4242                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4243                                         continue;
4244
4245                                 const char *grandchild_xml_name = NULL;
4246                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4247
4248                                 if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
4249                                         location_s *pSourceLocation = _get_location(grandchild);
4250                                         if (pSourceLocation == NULL) {
4251                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4252                                                 goto return_part;
4253                                         }
4254                                         pAlert->source = pSourceLocation;
4255                                 } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
4256                                         location_s *pTargetLocation = _get_location(grandchild);
4257                                         if (pTargetLocation == NULL) {
4258                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4259                                                 goto return_part;
4260                                         }
4261                                         pAlert->target = pTargetLocation;
4262                                 } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
4263
4264                                         WBXMLTreeNode *grandgrandchild = NULL;
4265                                         for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
4266                                                 if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE)
4267                                                         continue;
4268
4269                                                 const char *grandgrandchild_xml_name = NULL;
4270                                                 grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
4271
4272                                                 if (strcmp(grandgrandchild_xml_name, ELEMENT_ANCHOR) == 0) {
4273                                                         anchor_s *anchor = _get_anchor(grandgrandchild);
4274                                                         if (anchor == NULL) {
4275                                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4276                                                                 goto return_part;
4277                                                         }
4278                                                         pAlert->private.alert.anchor = anchor;
4279                                                 } else if (strcmp(grandgrandchild_xml_name, ELEMENT_MAXOBJSIZE) == 0) {
4280                                                         char *maxObjSize = NULL;
4281                                                         err = sync_agent_get_text_from_node(grandgrandchild, &maxObjSize);
4282                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4283                                                                 goto return_part;
4284                                                         }
4285                                                         _DEBUG_TRACE("MaxObjSize = [%s]", maxObjSize);
4286                                                         if (maxObjSize != NULL)
4287                                                                 pAlert->private.alert.max_obj_size = atoi(maxObjSize);
4288                                                 }
4289                                         }
4290                                 }
4291                         }
4292                 }
4293         }
4294
4295  return_part:
4296         if (err == SYNC_AGENT_PB_RETURN_OK) {
4297                 *content = pAlert;
4298         } else {
4299                 _DEBUG_ERROR("error");
4300                 free_command(pAlert);
4301         }
4302
4303         _EXTERN_FUNC_EXIT;
4304         return err;
4305 }
4306
4307 static sync_agent_pb_error_e _oma_ds_binder_sync_end_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4308 {
4309         _INNER_FUNC_ENTER;
4310
4311         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
4312
4313         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
4314         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
4315
4316         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4317
4318         /* get data from dom tree */
4319         command_s *pSyncEnd = (command_s *) calloc(1, sizeof(command_s));
4320         if (pSyncEnd == NULL) {
4321                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4322                 _DEBUG_ERROR("pSyncEnd is null");
4323                 goto return_part;
4324         }
4325
4326         pSyncEnd->type = COMMAND_TYPE_SYNC_END;;
4327         pSyncEnd->msg_id = pSyncHdr->message_id;
4328         pSyncEnd->ref_count = 1;
4329
4330  return_part:
4331         if (err == SYNC_AGENT_PB_RETURN_OK) {
4332                 *content = pSyncEnd;
4333         } else {
4334                 _DEBUG_ERROR("error");
4335                 free_command(pSyncEnd);
4336         }
4337
4338         _EXTERN_FUNC_EXIT;
4339         return err;
4340 }
4341
4342 static sync_agent_pb_error_e _oma_ds_binder_sync_start_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4343 {
4344         _INNER_FUNC_ENTER;
4345
4346         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
4347         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
4348
4349         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
4350         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
4351
4352         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4353
4354         /* get data from dom tree */
4355         command_s *pSync = (command_s *) calloc(1, sizeof(command_s));
4356         if (pSync == NULL) {
4357                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4358                 _DEBUG_ERROR("pSync is null");
4359                 goto return_part;
4360         }
4361
4362         pSync->type = COMMAND_TYPE_SYNC_START;;
4363         pSync->msg_id = pSyncHdr->message_id;
4364         pSync->ref_count = 1;
4365
4366         WBXMLTreeNode *child = NULL;
4367
4368         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
4369                 if (child->type != WBXML_TREE_ELEMENT_NODE)
4370                         continue;
4371
4372                 const char *child_xml_name = NULL;
4373                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
4374
4375                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
4376                         char *cmd_id = NULL;
4377                         err = sync_agent_get_text_from_node(child, &cmd_id);
4378                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4379                                 goto return_part;
4380                         }
4381                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
4382                         if (cmd_id != NULL)
4383                                 pSync->cmd_id = atoi(cmd_id);
4384                 } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
4385                         _DEBUG_TRACE("NoResp");
4386                         pSync->no_resp = 1;
4387                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
4388                         _DEBUG_TRACE("Cred\n");
4389                         cred_s *cred = NULL;
4390                         cred = __get_cred(child);
4391                         if (cred == NULL) {
4392                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4393                                 goto return_part;
4394                         }
4395                         pSync->cred = cred;
4396                 } else if (strcmp(child_xml_name, ELEMENT_TARGET) == 0) {
4397                         location_s *pTargetLocation = _get_location(child);
4398                         if (pTargetLocation == NULL) {
4399                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4400                                 goto return_part;
4401                         }
4402                         pSync->target = pTargetLocation;
4403                 } else if (strcmp(child_xml_name, ELEMENT_SOURCE) == 0) {
4404                         location_s *pSourceLocation = _get_location(child);
4405                         if (pSourceLocation == NULL) {
4406                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4407                                 goto return_part;
4408                         }
4409                         pSync->source = pSourceLocation;
4410                 } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
4411                         /*TODO meta */
4412                 } else if (strcmp(child_xml_name, ELEMENT_NUMBEROFCHANGES) == 0) {
4413                         char *numOfChanges = NULL;
4414                         err = sync_agent_get_text_from_node(child, &numOfChanges);
4415                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4416                                 goto return_part;
4417                         }
4418                         _DEBUG_TRACE("NumberOfChanges = [%s]", numOfChanges);
4419
4420                         pSync->private.sync.has_num_changed = 1;
4421                         if (numOfChanges != NULL)
4422                                 pSync->private.sync.num_changed = atoi(numOfChanges);
4423                 }
4424         }
4425
4426  return_part:
4427         if (err == SYNC_AGENT_PB_RETURN_OK) {
4428                 *content = pSync;
4429         } else {
4430                 _DEBUG_ERROR("error");
4431                 free_command(pSync);
4432         }
4433
4434         _EXTERN_FUNC_EXIT;
4435         return err;
4436 }
4437
4438 static sync_agent_pb_error_e _oma_ds_binder_add_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4439 {
4440         _INNER_FUNC_ENTER;
4441
4442         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
4443         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
4444
4445         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
4446         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
4447
4448         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4449
4450         item_s *item = NULL;
4451
4452         /* get data from dom tree */
4453         command_s *pAdd = (command_s *) calloc(1, sizeof(command_s));
4454         if (pAdd == NULL) {
4455                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4456                 _DEBUG_ERROR("pAdd is null");
4457                 goto return_part;
4458         }
4459
4460         pAdd->type = COMMAND_TYPE_ADD;;
4461         pAdd->msg_id = pSyncHdr->message_id;
4462         pAdd->private.change.type = CHANGE_ADD;
4463         pAdd->ref_count = 1;
4464
4465         WBXMLTreeNode *child = NULL;
4466
4467         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
4468                 if (child->type != WBXML_TREE_ELEMENT_NODE)
4469                         continue;
4470
4471                 const char *child_xml_name = NULL;
4472                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
4473
4474                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
4475                         char *cmd_id = NULL;
4476                         err = sync_agent_get_text_from_node(child, &cmd_id);
4477                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4478                                 goto return_part;
4479                         }
4480                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
4481                         if (cmd_id != NULL)
4482                                 pAdd->cmd_id = atoi(cmd_id);
4483                 } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
4484                         _DEBUG_TRACE("NoResp");
4485                         pAdd->no_resp = 1;
4486                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
4487                         _DEBUG_TRACE("Cred\n");
4488                         cred_s *cred = NULL;
4489                         cred = __get_cred(child);
4490                         if (cred == NULL) {
4491                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4492                                 goto return_part;
4493                         }
4494                         pAdd->cred = cred;
4495                 } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
4496                         WBXMLTreeNode *grandchild = NULL;
4497
4498                         if (item == NULL) {
4499                                 item = create_item();
4500                                 if (item == NULL) {
4501                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4502                                         goto return_part;
4503                                 }
4504                         }
4505
4506                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4507                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4508                                         continue;
4509
4510                                 const char *grandchild_xml_name = NULL;
4511                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4512
4513                                 if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
4514                                         char *contentType = NULL;
4515                                         err = sync_agent_get_text_from_node(grandchild, &contentType);
4516                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4517                                                 goto return_part;
4518                                         }
4519                                         _DEBUG_TRACE("Content Type = [%s]", contentType);
4520                                         if (contentType != NULL)
4521                                                 item->content_type = strdup(contentType);
4522                                 } else if (strcmp(grandchild_xml_name, ELEMENT_SIZE) == 0) {
4523                                         char *size = NULL;
4524                                         err = sync_agent_get_text_from_node(grandchild, &size);
4525                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4526                                                 goto return_part;
4527                                         }
4528                                         _DEBUG_TRACE("Size = [%s]", size);
4529                                         if (size != NULL)
4530                                                 item->size = atoi(size);
4531                                 }
4532                         }
4533                 } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
4534
4535                         if (item == NULL) {
4536                                 item = create_item();
4537                                 if (item == NULL) {
4538                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4539                                         goto return_part;
4540                                 }
4541                         }
4542
4543                         WBXMLTreeNode *grandchild = NULL;
4544                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4545                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4546                                         continue;
4547
4548                                 const char *grandchild_xml_name = NULL;
4549                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4550
4551                                 if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
4552                                         location_s *pSourceLocation = _get_location(grandchild);
4553                                         if (pSourceLocation == NULL) {
4554                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4555                                                 goto return_part;
4556                                         }
4557                                         item->source = pSourceLocation;
4558                                 } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
4559                                         location_s *pTargetLocation = _get_location(grandchild);
4560                                         if (pTargetLocation == NULL) {
4561                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4562                                                 goto return_part;
4563                                         }
4564                                         item->target = pTargetLocation;
4565                                 } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
4566                                         WBXMLTreeNode *grandgrandchild = NULL;
4567
4568                                         for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
4569                                                 if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE)
4570                                                         continue;
4571
4572                                                 const char *grandgrandchild_xml_name = NULL;
4573                                                 grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
4574
4575                                                 if (strcmp(grandgrandchild_xml_name, ELEMENT_TYPE) == 0) {
4576                                                         char *contentType = NULL;
4577                                                         err = sync_agent_get_text_from_node(grandgrandchild, &contentType);
4578                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4579                                                                 goto return_part;
4580                                                         }
4581                                                         _DEBUG_TRACE("Content Type = [%s]", contentType);
4582                                                         if (contentType != NULL)
4583                                                                 item->content_type = strdup(contentType);
4584                                                 } else if (strcmp(grandgrandchild_xml_name, ELEMENT_SIZE) == 0) {
4585                                                         char *size = NULL;
4586                                                         err = sync_agent_get_text_from_node(grandgrandchild, &size);
4587                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4588                                                                 goto return_part;
4589                                                         }
4590                                                         _DEBUG_TRACE("Size = [%s]", size);
4591                                                         if (size != NULL)
4592                                                                 item->size = atoi(size);
4593                                                 }
4594                                         }
4595                                 } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
4596                                         char *data = NULL;
4597                                         err = sync_agent_get_text_from_cdata_node(grandchild, &data);
4598                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4599                                                 goto return_part;
4600                                         }
4601                                         _DEBUG_TRACE("Data = [%s]", data);
4602                                         if (data != NULL)
4603                                                 item->private.data = strdup(data);
4604                                         item->data_type = ITEM_DATA;
4605                                 } else if (strcmp(grandchild_xml_name, ELEMENT_MOREDATA) == 0) {
4606                                         _DEBUG_TRACE("MoreData");
4607                                         item->more_data = 1;
4608                                 }
4609                         }
4610                         pAdd->private.change.items = g_list_append(pAdd->private.change.items, item);
4611                         item = NULL;
4612                 }
4613         }
4614
4615  return_part:
4616
4617         if (item != NULL)
4618                 free_item(item);
4619
4620         if (err == SYNC_AGENT_PB_RETURN_OK) {
4621                 *content = pAdd;
4622         } else {
4623                 _DEBUG_ERROR("error");
4624                 free_command(pAdd);
4625         }
4626
4627         _EXTERN_FUNC_EXIT;
4628         return err;
4629 }
4630
4631 static sync_agent_pb_error_e _oma_ds_binder_replace_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4632 {
4633         _INNER_FUNC_ENTER;
4634
4635         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
4636         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
4637
4638         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
4639         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
4640
4641         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4642         item_s *item = NULL;
4643
4644         /* get data from dom tree */
4645         command_s *pReplace = (command_s *) calloc(1, sizeof(command_s));
4646         if (pReplace == NULL) {
4647                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4648                 _DEBUG_ERROR("pReplace is null");
4649                 goto return_part;
4650         }
4651
4652         pReplace->type = COMMAND_TYPE_REPLACE;;
4653         pReplace->msg_id = pSyncHdr->message_id;
4654         pReplace->private.change.type = CHANGE_REPLACE;
4655         pReplace->ref_count = 1;
4656
4657         WBXMLTreeNode *child = NULL;
4658
4659         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
4660                 if (child->type != WBXML_TREE_ELEMENT_NODE)
4661                         continue;
4662
4663                 const char *child_xml_name = NULL;
4664                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
4665
4666                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
4667                         char *cmd_id = NULL;
4668                         err = sync_agent_get_text_from_node(child, &cmd_id);
4669                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4670                                 goto return_part;
4671                         }
4672                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
4673                         if (cmd_id != NULL)
4674                                 pReplace->cmd_id = atoi(cmd_id);
4675
4676                 } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
4677                         _DEBUG_TRACE("NoResp");
4678                         pReplace->no_resp = 1;
4679                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
4680                         _DEBUG_TRACE("Cred\n");
4681                         cred_s *cred = NULL;
4682                         cred = __get_cred(child);
4683                         if (cred == NULL) {
4684                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4685                                 goto return_part;
4686                         }
4687                         pReplace->cred = cred;
4688                 } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
4689
4690                         if (item == NULL) {
4691                                 item = create_item();
4692                                 if (item == NULL) {
4693                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4694                                         goto return_part;
4695                                 }
4696                         }
4697                         WBXMLTreeNode *grandchild = NULL;
4698                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4699                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4700                                         continue;
4701
4702                                 const char *grandchild_xml_name = NULL;
4703                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4704
4705                                 if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
4706                                         char *contentType = NULL;
4707                                         err = sync_agent_get_text_from_node(grandchild, &contentType);
4708                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4709                                                 goto return_part;
4710                                         }
4711                                         _DEBUG_TRACE("Content Type = [%s]", contentType);
4712                                         if (contentType != NULL)
4713                                                 item->content_type = strdup(contentType);
4714                                 } else if (strcmp(grandchild_xml_name, ELEMENT_SIZE) == 0) {
4715                                         char *size = NULL;
4716                                         err = sync_agent_get_text_from_node(grandchild, &size);
4717                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4718                                                 goto return_part;
4719                                         }
4720                                         _DEBUG_TRACE("Size = [%s]", size);
4721                                         if (size != NULL)
4722                                                 item->size = atoi(size);
4723                                 }
4724                         }
4725                 } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
4726
4727                         if (item == NULL) {
4728                                 item = create_item();
4729                                 if (item == NULL) {
4730                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4731                                         goto return_part;
4732                                 }
4733                         }
4734
4735                         WBXMLTreeNode *grandchild = NULL;
4736                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4737                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4738                                         continue;
4739
4740                                 const char *grandchild_xml_name = NULL;
4741                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4742
4743                                 if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
4744                                         location_s *pSourceLocation = _get_location(grandchild);
4745                                         if (pSourceLocation == NULL) {
4746                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4747                                                 goto return_part;
4748                                         }
4749                                         item->source = pSourceLocation;
4750                                 } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
4751                                         location_s *pTargetLocation = _get_location(grandchild);
4752                                         if (pTargetLocation == NULL) {
4753                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4754                                                 goto return_part;
4755                                         }
4756                                         item->target = pTargetLocation;
4757                                 } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
4758                                         WBXMLTreeNode *grandgrandchild = NULL;
4759
4760                                         for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
4761                                                 if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE)
4762                                                         continue;
4763
4764                                                 const char *grandgrandchild_xml_name = NULL;
4765                                                 grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
4766
4767                                                 if (strcmp(grandgrandchild_xml_name, ELEMENT_TYPE) == 0) {
4768                                                         char *contentType = NULL;
4769                                                         err = sync_agent_get_text_from_node(grandgrandchild, &contentType);
4770                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4771                                                                 goto return_part;
4772                                                         }
4773                                                         _DEBUG_TRACE("Content Type = [%s]", contentType);
4774                                                         if (contentType != NULL)
4775                                                                 item->content_type = strdup(contentType);
4776                                                 } else if (strcmp(grandgrandchild_xml_name, ELEMENT_SIZE) == 0) {
4777                                                         char *size = NULL;
4778                                                         err = sync_agent_get_text_from_node(grandgrandchild, &size);
4779                                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4780                                                                 goto return_part;
4781                                                         }
4782                                                         _DEBUG_TRACE("Size = [%s]", size);
4783                                                         if (size != NULL)
4784                                                                 item->size = atoi(size);
4785                                                 }
4786                                         }
4787
4788                                 } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
4789                                         char *data = NULL;
4790                                         err = sync_agent_get_text_from_cdata_node(grandchild, &data);
4791                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4792                                                 goto return_part;
4793                                         }
4794                                         _DEBUG_TRACE("Data = [%s]", data);
4795                                         if (data != NULL)
4796                                                 item->private.data = strdup(data);
4797                                         item->data_type = ITEM_DATA;
4798                                 }
4799                         }
4800                         pReplace->private.change.items = g_list_append(pReplace->private.change.items, item);
4801                         item = NULL;
4802                 }
4803         }
4804
4805  return_part:
4806
4807         if (item != NULL)
4808                 free_item(item);
4809
4810         if (err == SYNC_AGENT_PB_RETURN_OK) {
4811                 *content = pReplace;
4812         } else {
4813                 _DEBUG_ERROR("error");
4814                 free_command(pReplace);
4815         }
4816
4817         _EXTERN_FUNC_EXIT;
4818         return err;
4819 }
4820
4821 static sync_agent_pb_error_e _oma_ds_binder_delete_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4822 {
4823         _INNER_FUNC_ENTER;
4824         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4825
4826         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
4827         retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL");
4828
4829         sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder);
4830         retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL");
4831
4832         item_s *item = NULL;
4833
4834         /* get data from dom tree */
4835         command_s *pDelete = (command_s *) calloc(1, sizeof(command_s));
4836         if (pDelete == NULL) {
4837                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4838                 _DEBUG_ERROR("pDelete is null");
4839                 goto return_part;
4840         }
4841
4842         pDelete->type = COMMAND_TYPE_DELETE;
4843         pDelete->msg_id = pSyncHdr->message_id;
4844         pDelete->private.change.type = CHANGE_DELETE;
4845         pDelete->ref_count = 1;
4846
4847         WBXMLTreeNode *child = NULL;
4848
4849         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
4850                 if (child->type != WBXML_TREE_ELEMENT_NODE)
4851                         continue;
4852
4853                 const char *child_xml_name = NULL;
4854                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
4855
4856                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
4857                         char *cmd_id = NULL;
4858                         err = sync_agent_get_text_from_node(child, &cmd_id);
4859                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4860                                 goto return_part;
4861                         }
4862                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
4863                         if (cmd_id != NULL)
4864                                 pDelete->cmd_id = atoi(cmd_id);
4865                 } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
4866                         _DEBUG_TRACE("NoResp");
4867                         pDelete->no_resp = 1;
4868                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
4869                         _DEBUG_TRACE("Cred\n");
4870                         cred_s *cred = NULL;
4871                         cred = __get_cred(child);
4872                         if (cred == NULL) {
4873                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4874                                 goto return_part;
4875                         }
4876                         pDelete->cred = cred;
4877                 } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
4878                         WBXMLTreeNode *grandchild = NULL;
4879
4880                         /* create Item */
4881                         if (item == NULL) {
4882                                 item = create_item();
4883                                 if (item == NULL) {
4884                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4885                                         goto return_part;
4886                                 }
4887                         }
4888
4889                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4890                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4891                                         continue;
4892
4893                                 const char *grandchild_xml_name = NULL;
4894                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4895
4896                                 if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
4897                                         char *contentType = NULL;
4898                                         err = sync_agent_get_text_from_node(grandchild, &contentType);
4899                                         if (err != SYNC_AGENT_PB_RETURN_OK) {
4900                                                 goto return_part;
4901                                         }
4902                                         _DEBUG_TRACE("Content Type = [%s]", contentType);
4903                                         if (contentType != NULL)
4904                                                 item->content_type = strdup(contentType);
4905                                 }
4906                         }
4907                 } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
4908                         /* create Item */
4909                         if (item == NULL) {
4910                                 item = create_item();
4911                                 if (item == NULL) {
4912                                         err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4913                                         goto return_part;
4914                                 }
4915                         }
4916                         WBXMLTreeNode *grandchild = NULL;
4917
4918                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
4919                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
4920                                         continue;
4921
4922                                 const char *grandchild_xml_name = NULL;
4923                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
4924
4925                                 if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
4926                                         location_s *pSourceLocation = _get_location(grandchild);
4927                                         if (pSourceLocation == NULL) {
4928                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4929                                                 goto return_part;
4930                                         }
4931                                         item->source = pSourceLocation;
4932                                 } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
4933                                         location_s *pTargetLocation = _get_location(grandchild);
4934                                         if (pTargetLocation == NULL) {
4935                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4936                                                 goto return_part;
4937                                         }
4938                                         item->target = pTargetLocation;
4939                                 } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
4940
4941                                 } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
4942
4943                                 }
4944                         }
4945                         pDelete->private.change.items = g_list_append(pDelete->private.change.items, item);
4946                         item = NULL;
4947                 }
4948         }
4949
4950  return_part:
4951
4952         if (item != NULL)
4953                 free_item(item);
4954
4955         if (err == SYNC_AGENT_PB_RETURN_OK) {
4956                 *content = pDelete;
4957         } else {
4958                 _DEBUG_ERROR("error");
4959                 free_command(pDelete);
4960         }
4961
4962         _EXTERN_FUNC_EXIT;
4963         return err;
4964 }
4965
4966 static sync_agent_pb_error_e _oma_ds_binder_final_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4967 {
4968         _INNER_FUNC_ENTER;
4969         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4970
4971         int *pFinal = (int *)1;
4972         *content = pFinal;
4973
4974         _EXTERN_FUNC_EXIT;
4975         return err;
4976 }
4977
4978 static sync_agent_pb_error_e _oma_ds_binder_status_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content)
4979 {
4980         _INNER_FUNC_ENTER;
4981         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
4982
4983         retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL");
4984
4985         /* get data from dom tree */
4986         status_s *pStatus = (status_s *) calloc(1, sizeof(status_s));
4987         if (pStatus == NULL) {
4988                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
4989                 _DEBUG_ERROR("pStatus is null");
4990                 goto return_part;
4991         }
4992
4993         WBXMLTreeNode *child = NULL;
4994         for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
4995                 if (child->type != WBXML_TREE_ELEMENT_NODE)
4996                         continue;
4997                 const char *child_xml_name = NULL;
4998                 child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
4999
5000                 if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
5001                         char *cmd_id = NULL;
5002                         err = sync_agent_get_text_from_node(child, &cmd_id);
5003                         if (err != SYNC_AGENT_PB_RETURN_OK) {
5004                                 goto return_part;
5005                         }
5006                         _DEBUG_TRACE("CmdID = [%s]", cmd_id);
5007                         if (cmd_id != NULL)
5008                                 pStatus->cmd_id = atoi(cmd_id);
5009                 } else if (strcmp(child_xml_name, ELEMENT_MSGREF) == 0) {
5010                         char *msgref = NULL;
5011                         err = sync_agent_get_text_from_node(child, &msgref);
5012                         if (err != SYNC_AGENT_PB_RETURN_OK) {
5013                                 goto return_part;
5014                         }
5015                         _DEBUG_TRACE("MsgRef = [%s]", msgref);
5016                         if (msgref != NULL)
5017                                 pStatus->msg_ref = atoi(msgref);
5018                 } else if (strcmp(child_xml_name, ELEMENT_CMDREF) == 0) {
5019                         char *cmdref = NULL;
5020                         err = sync_agent_get_text_from_node(child, &cmdref);
5021                         if (err != SYNC_AGENT_PB_RETURN_OK) {
5022                                 goto return_part;
5023                         }
5024                         _DEBUG_TRACE("CmdRef = [%s]", cmdref);
5025                         if (cmdref != NULL)
5026                                 pStatus->cmd_ref = atoi(cmdref);
5027                 } else if (strcmp(child_xml_name, ELEMENT_CMD) == 0) {
5028                         char *cmd = NULL;
5029                         err = sync_agent_get_text_from_node(child, &cmd);
5030                         if (err != SYNC_AGENT_PB_RETURN_OK) {
5031                                 goto return_part;
5032                         }
5033                         _DEBUG_TRACE("Cmd = [%s]", cmd);
5034
5035                         pStatus->type = convert_command_type(cmd);
5036                 } else if (strcmp(child_xml_name, ELEMENT_TARGETREF) == 0) {
5037                         char *targetref = NULL;
5038                         location_s *location = NULL;
5039                         err = sync_agent_get_text_from_node(child, &targetref);
5040                         if (err != SYNC_AGENT_PB_RETURN_OK) {
5041                                 goto return_part;
5042                         }
5043                         _DEBUG_TRACE("TargetRef = [%s]", targetref);
5044
5045                         sa_error_type_e error = create_location(targetref, NULL, &location);
5046                         if (error != SA_INTERNAL_OK) {
5047                                 _DEBUG_ERROR("create_location() failed !, error = %d", error);
5048                                 goto return_part;
5049                         }
5050                         pStatus->target_ref = location;
5051                 } else if (strcmp(child_xml_name, ELEMENT_SOURCEREF) == 0) {
5052                         char *sourceref = NULL;
5053                         location_s *location = NULL;
5054                         err = sync_agent_get_text_from_node(child, &sourceref);
5055                         if (err != SYNC_AGENT_PB_RETURN_OK) {
5056                                 goto return_part;
5057                         }
5058                         _DEBUG_TRACE("SourceRef = [%s]", sourceref);
5059
5060                         sa_error_type_e error = create_location(sourceref, NULL, &location);
5061                         if (error != SA_INTERNAL_OK) {
5062                                 _DEBUG_ERROR("create_location() failed !, error = %d", error);
5063                                 goto return_part;
5064                         }
5065                         pStatus->source_ref = location;
5066                 } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
5067                         _DEBUG_TRACE("Cred\n");
5068                         cred_s *cred = NULL;
5069                         cred = __get_cred(child);
5070                         if (cred == NULL) {
5071                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
5072                                 goto return_part;
5073                         }
5074                         pStatus->cred = cred;
5075                 } else if (strcmp(child_xml_name, ELEMENT_CHAL) == 0) {
5076                         _DEBUG_TRACE("Chal\n");
5077                         chal_s *pChal = NULL;
5078                         pChal = _get_chal(child);
5079                         if (pChal == NULL) {
5080                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
5081                                 goto return_part;
5082                         }
5083                         pStatus->chal = pChal;
5084                 } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
5085                         char *data = NULL;
5086                         err = sync_agent_get_text_from_node(child, &data);
5087                         if (err != SYNC_AGENT_PB_RETURN_OK) {
5088                                 goto return_part;
5089                         }
5090                         _DEBUG_TRACE("Data = [%s]\n", data);
5091                         if (data != NULL)
5092                                 pStatus->data = strdup(data);
5093                 } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
5094                         WBXMLTreeNode *grandchild = NULL;
5095
5096                         for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
5097                                 if (grandchild->type != WBXML_TREE_ELEMENT_NODE)
5098                                         continue;
5099
5100                                 const char *grandchild_xml_name = NULL;
5101                                 grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
5102
5103                                 if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
5104                                         location_s *pSourceLocation = _get_location(grandchild);
5105                                         if (pSourceLocation == NULL) {
5106                                                 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
5107                                                 goto return_part;
5108                                         }
5109                                         pStatus->source_ref = pSourceLocation;
5110                                 } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
5111                                         /* need ? */
5112                                 } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
5113                                         /* need ? */
5114                                 }
5115                         }
5116                 }
5117         }
5118
5119  return_part:
5120         if (err == SYNC_AGENT_PB_RETURN_OK) {
5121                 *content = pStatus;
5122         } else {
5123                 _DEBUG_ERROR("error");
5124                 free_status(pStatus);
5125         }
5126
5127         _EXTERN_FUNC_EXIT;
5128         return err;
5129 }
5130
5131 sync_agent_pb_error_e init_oma_ds_1_2_binder_function_set(sync_agent_pb_protocol_binder_function_set_s ** binder_function_set)
5132 {
5133         _EXTERN_FUNC_ENTER;
5134
5135         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
5136
5137         err = sync_agent_init_binder_function_set(sizeof(oma_ds_binder_function_info) / sizeof(sync_agent_pb_function_info_s), (sync_agent_pb_function_info_s *) oma_ds_binder_function_info, binder_function_set);
5138
5139         _EXTERN_FUNC_EXIT;
5140         return err;
5141 }
5142
5143 void free_oma_ds_1_2_binder_function_set(sync_agent_pb_protocol_binder_function_set_s * binder_function_set)
5144 {
5145         _EXTERN_FUNC_ENTER;
5146
5147         sync_agent_free_binder_function_set(binder_function_set);
5148
5149         _EXTERN_FUNC_EXIT;
5150 }
5151
5152 sync_agent_pb_protocol_binder_info_s *oma_ds_1_2_binder_init(sync_agent_pb_protocol_binder_info_s * binder, sync_agent_pb_encoding_e enc, bool encode_xml_header,
5153                                                              bool use_strtbl, bool produce_anonymous, bool use_flow_mode, bool text_public_id, sync_agent_pb_protocol_binder_function_set_s * binder_function_set)
5154 {
5155         _EXTERN_FUNC_ENTER;
5156
5157         sync_agent_pb_protocol_binder_info_s *pOutBinder = NULL;
5158
5159         pOutBinder = sync_agent_init_protocol_binder(binder, SYNC_AGENT_PB_PROTOCOL_SYNCML_SYNCML12, NULL, enc, encode_xml_header, use_strtbl, produce_anonymous, use_flow_mode, text_public_id, NULL, NULL, binder_function_set);
5160
5161         if (pOutBinder == NULL) {
5162                 goto return_part;
5163         }
5164
5165  return_part:
5166
5167         _EXTERN_FUNC_EXIT;
5168         return pOutBinder;
5169 }
5170
5171 sync_agent_pb_error_e oma_ds_1_2_binder_append(sync_agent_pb_protocol_binder_info_s * binder, oma_ds_protocol_element_e protocol_element, Content_Ptr content)
5172 {
5173         _EXTERN_FUNC_ENTER;
5174
5175         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
5176
5177         err = sync_agent_append_element(binder, protocol_element, content);
5178
5179         _EXTERN_FUNC_EXIT;
5180         return err;
5181 }
5182
5183 void oma_ds_1_2_binder_terminate(sync_agent_pb_protocol_binder_info_s * binder)
5184 {
5185         _EXTERN_FUNC_ENTER;
5186
5187         sync_agent_destroy_protocol_binder(binder);
5188
5189         _EXTERN_FUNC_EXIT;
5190 }
5191
5192 sync_agent_pb_error_e oma_ds_1_2_binder_get_stream(sync_agent_pb_protocol_binder_info_s * binder, char **byte_stream, unsigned int *byte_stream_size)
5193 {
5194         _EXTERN_FUNC_ENTER;
5195
5196         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
5197
5198         err = sync_agent_get_stream_from_protocol_binder(binder, byte_stream, byte_stream_size);
5199         if (err != SYNC_AGENT_PB_RETURN_OK) {
5200                 goto return_part;
5201         }
5202
5203  return_part:
5204
5205         _EXTERN_FUNC_EXIT;
5206         return err;
5207 }
5208
5209 sync_agent_pb_error_e oma_ds_1_2_binder_get_stream_size(sync_agent_pb_protocol_binder_info_s * binder, unsigned int *byte_stream_size)
5210 {
5211
5212         _EXTERN_FUNC_ENTER;
5213
5214         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
5215
5216         err = sync_agent_get_stream_size_from_protocol_binder(binder, byte_stream_size);
5217
5218         _EXTERN_FUNC_EXIT;
5219         return err;
5220 }
5221
5222 sync_agent_pb_error_e oma_ds_1_2_binder_get_encoding(sync_agent_pb_protocol_binder_info_s * binder, sync_agent_pb_encoding_e * enc)
5223 {
5224         _EXTERN_FUNC_ENTER;
5225
5226         sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
5227
5228         err = sync_agent_get_encoding_from_protocol_binder(binder, enc);
5229
5230         _EXTERN_FUNC_EXIT;
5231         return err;
5232 }
5233
5234 sync_agent_pb_error_e reverse_oma_ds_1_2_binder_init(char *byte_stream,
5235                                                      unsigned int byte_stream_len, sync_agent_pb_decoding_e dec, sync_agent_pb_protocol_binder_function_set_s * binder_function_set, void *user_data, sync_agent_pb_protocol_binder_reverse_info_s ** binder)
5236 {
5237         _EXTERN_FUNC_ENTER;
5238
5239         sync_agent_pb_protocol_e protocol = SYNC_AGENT_PB_PROTOCOL_UNKNOWN;
5240         sync_agent_pb_error_e err = sync_agent_init_reverse_protocol_binder(byte_stream, byte_stream_len, dec,
5241                                                                             &protocol, binder_function_set, user_data, binder);
5242
5243         _EXTERN_FUNC_EXIT;
5244         return err;
5245 }
5246
5247 sync_agent_pb_error_e reverse_oma_ds_1_2_binder_next(sync_agent_pb_protocol_binder_reverse_info_s * pBinder, oma_ds_protocol_element_e * protocol_element, char **protocol_element_name, Content_Ptr * content)
5248 {
5249         _EXTERN_FUNC_ENTER;
5250
5251         sync_agent_pb_error_e err = sync_agent_next_element(pBinder,
5252                                                             protocol_element, protocol_element_name, content);
5253
5254         _EXTERN_FUNC_EXIT;
5255         return err;
5256 }