3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <sync_agent.h>
22 #include "common/dm_common.h"
23 #include "common/util/util.h"
24 #include "serviceadapter/sa_syncml_binders.h"
25 #include "serviceadapter/protocolbinder/syncml_protocol_binder.h"
26 #include "serviceadapter/sa_elements_internal.h"
27 #include "serviceadapter/sa_command_internal.h"
28 #include "serviceadapter/sa_util.h"
30 #ifndef OMADM_AGENT_LOG
32 #define LOG_TAG "OMA_DM_SA"
35 DM_ERROR syncml_objectbinder(SyncML * pSyncML, char **msg, unsigned int *msg_size)
41 retvm_if((pSyncML) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "pSyncML is NULL!!");
43 sync_agent_pb_protocol_binder_function_set_s *pBinder_function_set = NULL;
45 sync_agent_pb_error_e err = init_syncml_binder_function_set(&pBinder_function_set);
46 if (err != SYNC_AGENT_PB_RETURN_OK) {
47 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
51 sync_agent_pb_protocol_binder_info_s *pBinder = NULL;
52 pBinder = syncml_binder_init(pBinder, SYNC_AGENT_PB_ENCODING_WBXML_12, false, true, pBinder_function_set);
54 err = syncml_binder_append(pBinder, PE_SYNCML_START, NULL);
55 if (err != SYNC_AGENT_PB_RETURN_OK) {
56 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
60 err = syncml_binder_append(pBinder, PE_HEADER, pSyncML->hdr);
61 if (err != SYNC_AGENT_PB_RETURN_OK) {
62 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
65 err = syncml_binder_append(pBinder, PE_BODY_START, NULL);
66 if (err != SYNC_AGENT_PB_RETURN_OK) {
67 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
71 /* TODO : Status handling */
72 GList *status_iter = NULL;
73 Status *pStatus = NULL;
74 for (status_iter = pSyncML->status; status_iter != NULL; status_iter = g_list_next(status_iter)) {
75 pStatus = status_iter->data;
76 err = syncml_binder_append(pBinder, PE_STATUS, pStatus);
80 Command *pCommand = NULL;
81 OMA_DM_Protocol_Element protocol_element = PE_UNDEF;
82 for (iter = pSyncML->commands; iter != NULL; iter = g_list_next(iter)) {
83 pCommand = (Command *) (iter->data);
85 /* unsigned int estimate_size =0;
86 syncml_binder_get_estimate_doc_size(pBinder, &estimate_size);
87 _DEBUG_INFO(" ESTIMATE SIZE = %d\n", estimate_size);*/
89 CommandType type = pCommand->type;
91 case COMMAND_TYPE_UNKNOWN:
92 protocol_element = PE_UNDEF;
94 case COMMAND_TYPE_ALERT:
95 protocol_element = PE_ALERT;
97 case COMMAND_TYPE_ADD:
98 protocol_element = PE_ADD;
100 case COMMAND_TYPE_REPLACE:
101 protocol_element = PE_REPLACE;
103 case COMMAND_TYPE_DELETE:
104 protocol_element = PE_DELETE;
106 case COMMAND_TYPE_GET:
107 protocol_element = PE_GET;
109 case COMMAND_TYPE_RESULTS:
110 protocol_element = PE_RESULTS_START;
112 case COMMAND_TYPE_HEADER:
113 protocol_element = PE_HEADER;
115 case COMMAND_TYPE_EXEC:
116 protocol_element = PE_EXEC;
118 case COMMAND_TYPE_SEQUENCE:
119 protocol_element = PE_SEQUENCE;
121 case COMMAND_TYPE_ATOMIC:
122 protocol_element = PE_ATOMIC;
124 case COMMAND_TYPE_COPY:
125 protocol_element = PE_COPY;
131 err = syncml_binder_append(pBinder, protocol_element, pCommand);
132 if (err != SYNC_AGENT_PB_RETURN_OK) {
133 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
137 if (type == COMMAND_TYPE_RESULTS) {
138 err = syncml_binder_append(pBinder, PE_RESULTS_END, NULL);
139 if (err != SYNC_AGENT_PB_RETURN_OK) {
140 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
146 if (pSyncML->final == 1) {
147 err = syncml_binder_append(pBinder, PE_FINAL, NULL);
148 if (err != SYNC_AGENT_PB_RETURN_OK) {
149 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
154 err = syncml_binder_append(pBinder, PE_BODY_END, NULL);
155 if (err != SYNC_AGENT_PB_RETURN_OK) {
156 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
159 err = syncml_binder_append(pBinder, PE_SYNCML_END, NULL);
160 if (err != SYNC_AGENT_PB_RETURN_OK) {
161 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
164 syncml_binder_get_stream(pBinder, msg, msg_size);
167 unsigned int xml_len = 0;
168 err = sync_agent_get_xml_from_protocol_binder(pBinder, &xml, &xml_len);
169 if (err == SYNC_AGENT_PB_RETURN_OK) {
170 _DEBUG_INFO(" msg from client \n");
171 if (fputs(xml, stderr) == EOF) {
172 _DEBUG_INFO("debuging test error");
174 set_xml_to_file((xml), OMA_DM_MSG_PATH);
178 syncml_binder_terminate(pBinder);
180 if (err != SYNC_AGENT_PB_RETURN_OK) {
181 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
189 _DEBUG_INFO("error end %d \n", ret);
194 DM_ERROR reverse_syncml_objectbinder(SyncML ** pSyncML, char *recv_msg, unsigned int recv_msg_length, char **xml, unsigned int *xml_len)
198 DM_ERROR ret = DM_OK;
200 retvm_if((recv_msg) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "recv_msg is NULL!!");
202 sync_agent_pb_protocol_binder_function_set_s *pBinder_function_set = NULL;
204 sync_agent_pb_error_e err = init_syncml_binder_function_set(&pBinder_function_set);
205 sync_agent_pb_protocol_binder_reverse_info_s *pBinder = NULL;
206 err = reverse_syncml_binder_init(recv_msg, recv_msg_length, SYNC_AGENT_PB_DECODING_WBXML, pBinder_function_set, NULL, &pBinder);
208 if (err != SYNC_AGENT_PB_RETURN_OK) {
209 _DEBUG_INFO("reverse_oma_dm_1_2_binder_init error\n");
210 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;
213 /*_DEBUG_INFO( "pBinder = %x\n", pBinder);*/
216 unsigned int xml_size = 0; */
217 err = sync_agent_get_xml_from_reverse_protocol_binder(pBinder, xml, xml_len);
218 if (err == SYNC_AGENT_PB_RETURN_OK) {
219 fprintf(stderr, " msg from server \n");
220 if (fputs((*xml), stderr) == EOF) {
221 _DEBUG_INFO("debugging test error");
223 set_xml_to_file((*xml), OMA_DM_MSG_PATH);
227 OMA_DM_Protocol_Element protocol_element = PE_UNDEF;
228 char *protocol_element_name = NULL;
229 Content_Ptr pContent = NULL;
230 int sequence_Atomic = 0;
231 Command *tempCommand = NULL;
233 while (err == SYNC_AGENT_PB_RETURN_OK) {
234 err = reverse_syncml_binder_next(pBinder, &protocol_element, &protocol_element_name, &pContent);
236 if (err == SYNC_AGENT_PB_RETURN_HAS_NO_MORE_ELEMENT) {
240 switch (protocol_element) {
242 if (sequence_Atomic != 1)
243 (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
245 tempCommand->private.sequence_atomic.commands = g_list_append(tempCommand->private.sequence_atomic.commands, pContent);
250 if (sequence_Atomic != 1)
251 (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
253 tempCommand->private.sequence_atomic.commands = g_list_append(tempCommand->private.sequence_atomic.commands, pContent);
258 if (sequence_Atomic != 1)
259 (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
261 tempCommand->private.sequence_atomic.commands = g_list_append(tempCommand->private.sequence_atomic.commands, pContent);
264 case PE_SEQUENCE_START:
265 case PE_ATOMIC_START:
267 tempCommand = (Command *) pContent;
269 case PE_SEQUENCE_END:
272 (*pSyncML)->commands = g_list_append((*pSyncML)->commands, tempCommand);
276 if (sequence_Atomic != 1)
277 (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
279 tempCommand->private.sequence_atomic.commands = g_list_append(tempCommand->private.sequence_atomic.commands, pContent);
283 _DEBUG_INFO("reverse alert command");
284 if (sequence_Atomic != 1)
285 (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
287 tempCommand->private.sequence_atomic.commands = g_list_append(tempCommand->private.sequence_atomic.commands, pContent);
290 case PE_RESULTS_START:
291 (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
295 (*pSyncML)->status = g_list_append((*pSyncML)->status, pContent);
296 protocol_element = PE_UNDEF;
300 (*pSyncML)->hdr = pContent;
301 sync_agent_set_user_data_in_reverse_protocol_binder(pBinder, (*pSyncML)->hdr);
306 (*pSyncML)->final = (int)pContent;
314 sync_agent_destroy_reverse_protocol_binder(pBinder);
316 if (err != SYNC_AGENT_PB_RETURN_OK && err != SYNC_AGENT_PB_RETURN_HAS_NO_MORE_ELEMENT)
317 ret = COMMON_ERR_INTERNAL_BINDER_ERROR;