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.
22 #include <sync_agent.h>
25 #include "common/dm_common.h"
26 #include "common/dm_common_def.h"
27 #include "common/util/util.h"
28 #include "framework/ui-event-handler/user-interaction/user_interaction.h"
29 #include "serviceadapter/sa_session.h"
30 #include "serviceadapter/sa_session_internal.h"
31 #include "serviceadapter/sa_elements.h"
32 #include "serviceadapter/sa_elements_internal.h"
33 #include "serviceadapter/sa_command.h"
34 #include "serviceadapter/sa_command_internal.h"
35 #include "serviceadapter/dm-phase-handler/dm_phase_handler.h"
36 #include "mo-handler/dm_mo_common.h"
37 #include "mo-handler/dm_mo_handler.h"
38 #include "dm-engine/dm_common_engine.h"
40 #ifndef OMADM_AGENT_LOG
42 #define LOG_TAG "OMA_DM_SA"
45 //#define DEFAULT_SERVER_MAXMSGSIZE 61440
46 #define DEFAULT_SERVER_MAXMSGSIZE 5120
48 static DM_ERROR _receive_alert_status(Session * session, Status * status);
49 static DM_ERROR _receive_results_status(Session * session, Status * status);
51 static DM_ERROR _receive_alert_cmd(Session * session, Command * command);
52 static DM_ERROR _receive_get_cmd(Session * session, Command * command);
53 static DM_ERROR _receive_results_cmd(Session * session, Command * command);
54 static DM_ERROR _receive_changes_cmd(Session * session, Command * command);
55 static DM_ERROR _receive_exec_cmd(Session * session, Command * command);
56 static DM_ERROR _receive_atomic_cmd(Session * session, Command * command);
57 static DM_ERROR _receice_sequence_cmd(Session * session, Command * command);
59 static DM_ERROR __receive_get_property_cmd(char *server_id, char *full_path, char *real_full_path, propoerty_type pr_type, Item ** pItem, int *resultStatus);
60 static DM_ERROR __rollback_atomic(Session * session, Command * pCommand);
61 static DM_ERROR __userInteration_operation(Command * command, GList ** response, int *result_status);
63 static void _free_pending_statuses(GList * pendingStatus);
64 static void __free_pending_status(PendingStatus * pendingStatus);
66 static void _set_hmac_value(char **key, char *value, int size);
68 static DM_ERROR _receive_get_cmd(Session * session, Command * command)
74 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
75 retvm_if((command) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "command is NULL!!");
76 retvm_if((command->private.access.items) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "command->private.access.items is NULL!!");
78 int resultStatus = DM_OK;
81 Command *pCommand = NULL;
83 char *full_path = NULL;
86 ret = create_results_cmd(session, &pCommand);
90 set_resultscommand_msgref(pCommand, command->msgID);
91 set_resultscommand_cmdref(pCommand, command->cmdID);
96 char *contenttype = NULL;
98 unsigned int size = 0;
102 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
103 /* URL length over size : 414 error */
104 for (iter = command->private.access.items; iter != NULL; iter = g_list_next(iter)) {
108 _DEBUG_TRACE("item null");
109 resultStatus = DM_ERR_NOT_FOUND;
113 char *target = get_location_locuri(item->target);
114 if (target != NULL) {
115 full_path = g_strdup(target);
118 GList *pItems = NULL;
119 GetType gettype = GET_TYPE_NOMAL;
120 char *real_full_path = NULL;
122 ret = get_type_mo_tree(full_path, &gettype, &real_full_path);
129 _DEBUG_TRACE(" get_type_nomal \n");
131 err_code = sync_agent_is_exist_mo(full_path, &is_mo);
132 _DEBUG_TRACE("is existed mo : %d", err_code);
133 _DEBUG_TRACE("is mo : %d", is_mo);
135 _DEBUG_TRACE("NOT EXIST MO");
136 resultStatus = DM_ERR_NOT_FOUND;
139 _DEBUG_TRACE("EXIST MO");
142 err_code = sync_agent_check_acl_value(full_path, SYNC_AGENT_DM_MO_ACCESSTYPE_GET, session->pServer_id, &error_acl);
143 _DEBUG_TRACE("sync agent acl result : %d", err_code);
144 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
145 resultStatus = DM_ERR_NOT_FOUND;
148 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
149 if (error_acl == 0) {
150 _DEBUG_TRACE("ACL PERMISSION ERROR");
151 resultStatus = DM_ERR_PERMISSION_DENIED;
153 } else if (error_acl == 1) {
154 _DEBUG_TRACE("accesstype permission ERROR");
155 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
158 _DEBUG_TRACE("ACL PERMISSION");
159 ret = get_mo_node_format_contenttype(full_path, &format, &contenttype);
163 ret = get_mo_data(full_path, &data);
169 if (session->targetMaxMsgSize - DEFAULT_MORE_REST_SIZE < size) {
170 _DEBUG_TRACE("set more data ");
175 ret = construct_Item(full_path, format, contenttype, data, size, moreData, &pItem);
179 pCommand->private.results.items = g_list_append(pCommand->private.results.items, pItem);
183 case GET_TYPE_STRUCT:
185 _DEBUG_TRACE(" get_type_struct \n");
186 err_code = sync_agent_is_exist_mo(real_full_path, &is_mo);
187 _DEBUG_TRACE("is existed mo : %d", err_code);
188 _DEBUG_TRACE("is mo : %d", is_mo);
190 str_free(&real_full_path);
191 _DEBUG_TRACE("NOT EXIST MO");
192 resultStatus = DM_ERR_NOT_FOUND;
195 _DEBUG_TRACE("EXIST MO");
198 err_code = sync_agent_check_acl_value(real_full_path, SYNC_AGENT_DM_MO_ACCESSTYPE_GET, session->pServer_id, &error_acl);
199 _DEBUG_TRACE("sync agent acl result : %d", err_code);
200 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
201 str_free(&real_full_path);
202 _DEBUG_TRACE("acl get fail");
203 resultStatus = DM_ERR_NOT_FOUND;
206 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
207 if (error_acl == 0) {
208 _DEBUG_TRACE("ACL PERMISSION ERROR");
209 resultStatus = DM_ERR_PERMISSION_DENIED;
210 //free_command(pCommand);
212 } else if (error_acl == 1) {
213 _DEBUG_TRACE("accesstype PERMISSION ERROR");
214 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
217 _DEBUG_TRACE("ACL PERMISSION");
218 ret = get_struct(real_full_path, &pItems);
220 str_free(&real_full_path);
224 str_free(&real_full_path);
225 pCommand->private.results.items = pItems;
229 case GET_TYPE_STRUCTDATA:
231 err_code = sync_agent_is_exist_mo(real_full_path, &is_mo);
232 _DEBUG_TRACE("is existed mo : %d", err_code);
233 _DEBUG_TRACE("is mo : %d", is_mo);
235 str_free(&real_full_path);
236 _DEBUG_TRACE("NOT EXIST MO");
237 resultStatus = DM_ERR_NOT_FOUND;
240 _DEBUG_TRACE("EXIST MO");
242 _DEBUG_TRACE(" get_type_structdata \n");
244 err_code = sync_agent_check_acl_value(real_full_path, SYNC_AGENT_DM_MO_ACCESSTYPE_GET, session->pServer_id, &error_acl);
245 _DEBUG_TRACE("sync agent acl result : %d", err_code);
246 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
247 str_free(&real_full_path);
248 _DEBUG_TRACE("acl get fail");
249 resultStatus = DM_ERR_NOT_FOUND;
252 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
253 if (error_acl == 0) {
254 _DEBUG_TRACE("ACL PERMISSION ERROR");
255 resultStatus = DM_ERR_PERMISSION_DENIED;
256 //free_command(pCommand);
258 } else if (error_acl == 1) {
259 _DEBUG_TRACE("accesstype PERMISSION ERROR");
260 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
263 _DEBUG_TRACE("ACL PERMISSION");
264 ret = get_structdata(real_full_path, &pItems);
266 str_free(&real_full_path);
270 str_free(&real_full_path);
271 pCommand->private.results.items = pItems;
277 _DEBUG_TRACE(" get_type_tnds \n");
280 err_code = sync_agent_is_exist_mo(real_full_path, &is_mo);
281 _DEBUG_TRACE("is existed mo : %d", err_code);
283 str_free(&real_full_path);
284 _DEBUG_TRACE("NOT EXIST MO");
285 resultStatus = DM_ERR_NOT_FOUND;
288 _DEBUG_TRACE("EXIST MO");
291 err_code = sync_agent_check_acl_value(real_full_path, SYNC_AGENT_DM_MO_ACCESSTYPE_GET, session->pServer_id, &error_acl);
292 _DEBUG_TRACE("sync agent acl result : %d", err_code);
293 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
294 str_free(&real_full_path);
295 _DEBUG_TRACE("acl get fail");
296 resultStatus = DM_ERR_NOT_FOUND;
299 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
300 if (error_acl == 0) {
301 _DEBUG_TRACE("ACL PERMISSION ERROR");
302 resultStatus = DM_ERR_PERMISSION_DENIED;
303 //free_command(pCommand);
305 } else if (error_acl == 1) {
306 _DEBUG_TRACE("accesstype PERMISSION ERROR");
307 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
310 _DEBUG_TRACE("ACL PERMISSION");
311 const char *format = ELEMENT_XML;
312 const char *contenttype = ELEMENT_DMTNDS_XML;
313 char *output_stream = NULL;
314 unsigned int size = 0;
318 ret = get_tnds(ELEMENT_DMTNDS_XML, full_path, &output_stream, &size);
322 _DEBUG_TRACE("max size : %d", session->targetMaxMsgSize);
323 _DEBUG_TRACE("data size : %d", size);
324 if (output_stream != NULL && session->targetMaxMsgSize - DEFAULT_MORE_REST_SIZE < size) {
325 _DEBUG_TRACE("set more data ");
329 ret = construct_Item(real_full_path, format, contenttype, output_stream, size, moreData, &pItem);
331 str_free(&real_full_path);
335 str_free(&real_full_path);
336 _DEBUG_TRACE("add cmd item");
337 pCommand->private.results.items = g_list_append(pCommand->private.results.items, pItem);
341 case GET_TYPE_ACL_PROP:
343 ret = __receive_get_property_cmd(session->pServer_id, full_path, real_full_path, PROP_TYPE_ACL, &pItem, &resultStatus);
344 if (ret != DM_OK || resultStatus != DM_OK) {
345 str_free(&real_full_path);
348 str_free(&real_full_path);
349 _DEBUG_TRACE("add cmd item");
350 pCommand->private.results.items = g_list_append(pCommand->private.results.items, pItem);
353 case GET_TYPE_SIZE_PROP:
355 ret = __receive_get_property_cmd(session->pServer_id, full_path, real_full_path, PROP_TYPE_SIZE, &pItem, &resultStatus);
356 if (ret != DM_OK || resultStatus != DM_OK) {
357 str_free(&real_full_path);
360 str_free(&real_full_path);
361 _DEBUG_TRACE("add cmd item");
362 pCommand->private.results.items = g_list_append(pCommand->private.results.items, pItem);
365 case GET_TYPE_TYPE_PROP:
367 ret = __receive_get_property_cmd(session->pServer_id, full_path, real_full_path, PROP_TYPE_TYPE, &pItem, &resultStatus);
368 if (ret != DM_OK || resultStatus != DM_OK) {
369 str_free(&real_full_path);
372 str_free(&real_full_path);
373 _DEBUG_TRACE("add cmd item");
374 pCommand->private.results.items = g_list_append(pCommand->private.results.items, pItem);
377 case GET_TYPE_FORMAT_PROP:
379 ret = __receive_get_property_cmd(session->pServer_id, full_path, real_full_path, PROP_TYPE_FORMAT, &pItem, &resultStatus);
380 if (ret != DM_OK || resultStatus != DM_OK) {
381 str_free(&real_full_path);
384 str_free(&real_full_path);
385 _DEBUG_TRACE("add cmd item");
386 pCommand->private.results.items = g_list_append(pCommand->private.results.items, pItem);
389 case GET_TYPE_NAME_PROP:
391 ret = __receive_get_property_cmd(session->pServer_id, full_path, real_full_path, PROP_TYPE_NAME, &pItem, &resultStatus);
392 if (ret != DM_OK || resultStatus != DM_OK) {
393 str_free(&real_full_path);
396 str_free(&real_full_path);
397 _DEBUG_TRACE("add cmd item");
398 pCommand->private.results.items = g_list_append(pCommand->private.results.items, pItem);
403 _DEBUG_TRACE(" get_type_default \n");
407 session->resultsCommand = g_list_append(session->resultsCommand, pCommand);
408 _DEBUG_TRACE("add session result command result command list length : %d", g_list_length(session->resultsCommand));
410 ret = create_newstatus(session, resultStatus, command, item->source, item->target, COMMAND_TYPE_GET, &temp);
414 session->status = g_list_append(session->status, temp);
416 str_free(&full_path);
425 str_free(&full_path);
426 free_command(pCommand);
427 _DEBUG_TRACE(" error : %d\n", ret);
430 ret = create_newstatus(session, resultStatus, command, item->source, item->target, COMMAND_TYPE_GET, &temp);
434 ret = create_newstatus(session, resultStatus, command, command->source, command->target, COMMAND_TYPE_GET, &temp);
439 session->status = g_list_append(session->status, temp);
451 static DM_ERROR __receive_get_property_cmd(char *server_id, char *full_path, char *real_full_path, propoerty_type pr_type, Item ** pItem, int *resultStatus)
455 DM_ERROR ret = DM_OK;
457 retvm_if((server_id) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "server_id is NULL!!");
458 retvm_if((full_path) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "full_path is NULL!!");
459 retvm_if((real_full_path) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "real_full_path is NULL!!");
461 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
465 char *contenttype = NULL;
467 unsigned int size = 0;
469 _DEBUG_TRACE(" get property ");
471 err_code = sync_agent_is_exist_mo(real_full_path, &is_mo);
472 _DEBUG_TRACE("is existed mo : %d", err_code);
474 _DEBUG_TRACE("NOT EXIST MO");
475 *resultStatus = DM_ERR_NOT_FOUND;
478 _DEBUG_TRACE("EXIST MO");
481 err_code = sync_agent_check_acl_value(real_full_path, SYNC_AGENT_DM_MO_ACCESSTYPE_GET, server_id, &error_acl);
482 _DEBUG_TRACE("sync agent acl result : %d", err_code);
483 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
484 _DEBUG_TRACE("acl get fail");
485 *resultStatus = DM_ERR_NOT_FOUND;
488 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
489 if (error_acl == 0) {
490 _DEBUG_TRACE("ACL PERMISSION ERROR");
491 *resultStatus = DM_ERR_PERMISSION_DENIED;
492 //free_command(pCommand);
494 } else if (error_acl == 1) {
495 _DEBUG_TRACE("accesstype PERMISSION ERROR");
496 *resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
499 _DEBUG_TRACE("ACL PERMISSION");
501 ret = get_mo_node_format_contenttype(real_full_path, &format, &contenttype);
505 char *property = NULL;
506 ret = get_mo_node_property(real_full_path, pr_type, &property);
508 *resultStatus = DM_ERR_PERMISSION_DENIED;
509 //str_free(&real_full_path);
512 _DEBUG_TRACE("property value : %s", property);
513 ret = construct_Item(full_path, format, contenttype, property, size, moreData, pItem);
518 _DEBUG_TRACE(" end %d", ret);
523 _DEBUG_TRACE(" end eror : %d", ret);
528 static DM_ERROR _receive_alert_cmd(Session * session, Command * command)
532 DM_ERROR ret = DM_OK;
534 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
535 retvm_if((command) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "command is NULL!!");
538 int result_status = DM_OK;
539 GList *response = NULL;
541 int alert_data = command->private.alert.type; //atoi(item->private.data);
543 if (DM_ALERT_DISPLAY <= alert_data && DM_ALERT_MULTIPLE_CHOICE >= alert_data) {
544 _DEBUG_TRACE("alert ui");
545 ret = __userInteration_operation(command, &response, &result_status);
546 _DEBUG_TRACE("status : %d", result_status);
548 } else if (DM_ALERT_NEXT_MESSAGE <= alert_data && DM_ALERT_MULTIPLE_CHOICE > alert_data) {
549 _DEBUG_TRACE("result status : %d", result_status);
555 result_status = DM_ERR_NOT_EXECUTED;
559 ret = create_newstatus(session, result_status, command, command->source, command->target, COMMAND_TYPE_ALERT, &temp);
564 switch (alert_data) {
565 case DM_ALERT_DISPLAY:
566 case DM_ALERT_CONFIRM_OR_REJECT:
568 case DM_ALERT_TEXT_INPUT:
569 case DM_ALERT_SINGLE_CHOICE:
570 case DM_ALERT_MULTIPLE_CHOICE:
575 if (response != NULL) {
576 _DEBUG_TRACE("--------------------response data existed--------------------");
577 for (iter = response; iter != NULL; iter = g_list_next(iter)) {
578 if (iter->data != NULL) {
580 value = strdup((char *)iter->data);
581 ret = create_item_data(value, strlen(value), &pItem);
583 if (temp->data != NULL) {
584 str_free(&(temp->data));
586 temp->data = g_strdup_printf("%d", DM_ERR_NOT_EXECUTED);
590 temp->items = g_list_append(temp->items, pItem);
594 _DEBUG_TRACE("--------------------response data not existed--------------------");
604 session->status = g_list_append(session->status, temp);
610 ret = create_newstatus(session, result_status, command, command->source, command->target, COMMAND_TYPE_ALERT, &temp);
615 session->status = g_list_append(session->status, temp);
616 _DEBUG_TRACE(" error : %d\n", ret);
622 _DEBUG_TRACE(" error : %d\n", ret);
627 static DM_ERROR _receive_results_cmd(Session * session, Command * command)
631 DM_ERROR ret = DM_OK;
638 static DM_ERROR _receive_changes_cmd(Session * session, Command * command)
642 DM_ERROR ret = DM_OK;
644 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
645 retvm_if((command) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "command is NULL!!");
647 ChangeType type = command->private.change.type;
648 _DEBUG_TRACE(" start command type : %d\n", type);
650 int resultStatus = DM_OK;
653 GList *item_iter = NULL;
655 char *targetUrl = NULL;
656 char *sourceUrl = NULL;
658 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
660 char *real_full_path = NULL;
661 GetType gettype = GET_TYPE_NOMAL;
663 for (item_iter = command->private.change.items; item_iter != NULL; item_iter = g_list_next(item_iter)) {
664 item = item_iter->data;
666 targetUrl = get_location_locuri(item->target);
670 _DEBUG_TRACE(" add command \n");
671 err_code = sync_agent_is_exist_mo(targetUrl, &is_mo);
672 _DEBUG_TRACE("is exist result : %d", err_code);
673 _DEBUG_TRACE("is mo : %d", is_mo);
675 resultStatus = DM_ERR_ALEADY_EXISTS;
679 err_code = sync_agent_check_acl_value(targetUrl, SYNC_AGENT_DM_MO_ACCESSTYPE_ADD, session->pServer_id, &error_acl);
680 _DEBUG_TRACE("sync agent acl result : %d", err_code);
681 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
682 if (err_code == SYNC_AGENT_DM_MO_NOT_EXIST_NODE) {
685 resultStatus = DM_ERR_PERMISSION_DENIED;
689 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
690 if (error_acl == 0) {
691 _DEBUG_TRACE("ACL PERMISSION ERROR");
692 resultStatus = DM_ERR_PERMISSION_DENIED;
694 } else if (error_acl == 1) {
695 _DEBUG_TRACE("accesstype PERMISSION ERROR");
696 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
699 _DEBUG_TRACE("ACL PERMISSION");
700 ret = add_itemtomo(item, session->pServer_id);
708 _DEBUG_TRACE(" replace command \n");
710 ret = get_type_mo_tree(targetUrl, &gettype, &real_full_path);
717 _DEBUG_TRACE("nomal type : %d", gettype);
718 err_code = sync_agent_is_exist_mo(targetUrl, &is_mo);
719 _DEBUG_TRACE("is existed mo: %d, result: %d", is_mo, err_code);
721 _DEBUG_TRACE("NOT EXIST MO");
722 resultStatus = DM_ERR_NOT_FOUND;
726 err_code = sync_agent_check_acl_value(targetUrl, SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE, session->pServer_id, &error_acl);
727 _DEBUG_TRACE("sync agent acl result : %d", err_code);
728 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
729 _DEBUG_TRACE("acl get fail");
730 resultStatus = DM_ERR_NOT_FOUND;
733 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
734 if (error_acl == 0) {
735 _DEBUG_TRACE("ACL PERMISSION ERROR");
736 resultStatus = DM_ERR_PERMISSION_DENIED;
738 } else if (error_acl == 1) {
739 _DEBUG_TRACE("accesstype PERMISSION ERROR");
740 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
743 _DEBUG_TRACE("ACL PERMISSION");
744 ret = check_mo_scope(targetUrl);
749 ret = replace_itemtomo(item);
756 case GET_TYPE_ACL_PROP:
758 _DEBUG_TRACE(" property type : %d", gettype);
759 err_code = sync_agent_is_exist_mo(real_full_path, &is_mo);
760 _DEBUG_TRACE("is existed mo : %d", err_code);
762 _DEBUG_TRACE("NOT EXIST MO");
763 resultStatus = DM_ERR_NOT_FOUND;
766 /*do not check acl for replace property */
767 /*err_code = sync_agent_check_acl_value(real_full_path, SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE, session->pServer_id, &error_acl);
768 _DEBUG_TRACE("sync agent acl result : %d", err_code);
769 if(err_code != SYNC_AGENT_DM_MO_SUCCESS) {
770 resultStatus = DM_ERR_NOT_FOUND;
775 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
777 _DEBUG_TRACE("ACL PERMISSION ERROR");
778 resultStatus = DM_ERR_PERMISSION_DENIED;
780 } else if(error_acl == 1) {
781 _DEBUG_TRACE("accesstype PERMISSION ERROR");
782 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
785 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", 2);
786 ret = check_mo_scope(real_full_path);
791 //check_scope == 1 (dynamic)
792 ret = replace_itemtomo(item);
799 case GET_TYPE_NAME_PROP:
800 case GET_TYPE_TYPE_PROP:
801 case GET_TYPE_FORMAT_PROP:
802 case GET_TYPE_SIZE_PROP:
804 _DEBUG_TRACE(" property type : %d", gettype);
805 err_code = sync_agent_is_exist_mo(real_full_path, &is_mo);
806 _DEBUG_TRACE("is existed mo : %d", err_code);
808 _DEBUG_TRACE("NOT EXIST MO");
809 resultStatus = DM_ERR_NOT_FOUND;
812 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
816 _DEBUG_TRACE("replace type error");
821 _DEBUG_TRACE(" delete command \n");
822 err_code = sync_agent_is_exist_mo(targetUrl, &is_mo);
823 _DEBUG_TRACE("is existed mo : %d", err_code);
825 _DEBUG_TRACE("NOT EXIST MO");
826 resultStatus = DM_ERR_NOT_FOUND;
831 err_code = sync_agent_check_acl_value(targetUrl, SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE, session->pServer_id, &error_acl);
832 _DEBUG_TRACE("sync agent acl result : %d", err_code);
833 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
834 _DEBUG_TRACE("acl get fail");
835 resultStatus = DM_ERR_NOT_FOUND;
838 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
839 if (error_acl == 0) {
840 _DEBUG_TRACE("ACL PERMISSION ERROR");
841 resultStatus = DM_ERR_PERMISSION_DENIED;
843 } else if (error_acl == 1) {
844 _DEBUG_TRACE("accesstype PERMISSION ERROR");
845 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
848 _DEBUG_TRACE("ACL PERMISSION");
849 ret = check_mo_scope(targetUrl);
853 ret = delete_itemtomo(item);
861 _DEBUG_TRACE(" copy command \n");
863 sourceUrl = get_location_locuri(item->source);
864 if (sourceUrl != NULL) {
865 err_code = sync_agent_is_exist_mo(sourceUrl, &is_mo);
866 _DEBUG_TRACE("is existed mo : %d", err_code);
868 _DEBUG_TRACE("NOT EXIT MO");
869 resultStatus = DM_ERR_NOT_FOUND;
873 err_code = sync_agent_check_acl_value(sourceUrl, SYNC_AGENT_DM_MO_ACCESSTYPE_COPY, session->pServer_id, &error_acl);
874 _DEBUG_TRACE("sync agent acl result : %d", err_code);
875 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
876 _DEBUG_TRACE("acl get fail");
877 resultStatus = DM_ERR_NOT_FOUND;
880 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
881 if (error_acl == 0) {
882 _DEBUG_TRACE("ACL PERMISSION ERROR");
883 resultStatus = DM_ERR_PERMISSION_DENIED;
885 } else if (error_acl == 1) {
886 _DEBUG_TRACE("accesstype PERMISSION ERROR");
887 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
890 err_code = sync_agent_check_acl_value(targetUrl, SYNC_AGENT_DM_MO_ACCESSTYPE_COPY, session->pServer_id, &error_acl);
891 _DEBUG_TRACE("sync agent acl result : %d", err_code);
892 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
893 _DEBUG_TRACE("acl get fail");
894 resultStatus = DM_ERR_NOT_FOUND;
897 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
898 if (error_acl == 0) {
899 _DEBUG_TRACE("ACL PERMISSION ERROR");
900 resultStatus = DM_ERR_PERMISSION_DENIED;
902 } else if (error_acl == 1) {
903 _DEBUG_TRACE("accesstype PERMISSION ERROR");
904 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
907 _DEBUG_TRACE("ACL PERMISSION");
908 ret = copy_itemtomo(item);
921 ret = create_newstatus(session, resultStatus, command, item->source, item->target, command->type, &temp);
924 session->status = g_list_append(session->status, temp);
927 str_free(&(real_full_path));
932 ret = create_newstatus(session, resultStatus, command, command->source, command->target, command->type, &temp);
935 session->status = g_list_append(session->status, temp);
937 str_free(&(real_full_path));
938 _DEBUG_TRACE(" error : %d\n", ret);
944 str_free(&(real_full_path));
945 _DEBUG_TRACE(" error : %d\n", ret);
950 static DM_ERROR _receive_exec_cmd(Session * session, Command * command)
954 DM_ERROR ret = DM_OK;
956 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
957 retvm_if((command) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "command is NULL!!");
959 int resultStatus = DM_ERR_ACCEPTED_FOR_PROCESSING;
961 char *targetUrl = NULL;
963 item = command->private.exec.item;
965 char *pCorrelator = NULL;
966 char *server_id = NULL;
968 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
970 _DEBUG_TRACE("----------------------------------------------------------------------------exec cmd --------------------------------------------------------------------------- ");
971 targetUrl = get_location_locuri(command->private.exec.item->target);
974 err_code = sync_agent_is_exist_mo(targetUrl, &is_mo);
975 _DEBUG_TRACE("is existed mo : %d", err_code);
977 _DEBUG_TRACE("NOT EXIT MO");
978 resultStatus = DM_ERR_NOT_FOUND;
983 err_code = sync_agent_check_acl_value(targetUrl, SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC, session->pServer_id, &error_acl);
984 _DEBUG_TRACE("sync agent acl result : %d", err_code);
985 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
986 _DEBUG_TRACE("acl get fail");
987 resultStatus = DM_ERR_NOT_FOUND;
990 _DEBUG_TRACE("----------------------------------------------------------------------------------------ACL RETURN--------------------------------------------------- : %d", error_acl);
991 if (error_acl == 0) {
992 _DEBUG_TRACE("ACL PERMISSION ERROR");
993 resultStatus = DM_ERR_PERMISSION_DENIED;
995 } else if (error_acl == 1) {
996 _DEBUG_TRACE("accesstype PERMISSION ERROR");
997 resultStatus = DM_ERR_COMMAND_NOT_ALLOWED;
1000 _DEBUG_TRACE("ACL PERMISSION");
1001 targetUrl = get_location_locuri(item->target);
1002 pCorrelator = command->private.exec.correlator;
1003 server_id = session->pServer_id;
1005 ret = engine_start(server_id, targetUrl, pCorrelator, &(session->service_engine_id), &resultStatus);
1006 _DEBUG_TRACE("--------------------------------------------------------engine_start off %d-----------------------------------------------------------------\n", ret);
1008 //ret = DM_ERR_NOT_FOUND;
1014 ret = create_newstatus(session, resultStatus, command, item->source, item->target, COMMAND_TYPE_EXEC, &temp);
1017 session->status = g_list_append(session->status, temp);
1023 ret = create_newstatus(session, resultStatus, command, item->source, item->target, COMMAND_TYPE_EXEC, &temp);
1026 session->status = g_list_append(session->status, temp);
1028 _DEBUG_TRACE(" error : %d\n", ret);
1032 _DEBUG_TRACE(" error : %d\n", ret);
1038 static DM_ERROR _receice_sequence_cmd(Session * session, Command * command)
1042 DM_ERROR ret = DM_OK;
1044 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
1045 retvm_if((command) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "command is NULL!!");
1047 int resultStatus = DM_OK;
1048 //sync_agent_dm_mo_error_e mo_ret = sync_agent_begin_transaction_mo();
1050 Status *temp = NULL;
1051 ret = create_newstatus(session, resultStatus, command, command->source, command->target, COMMAND_TYPE_SEQUENCE, &temp);
1055 session->status = g_list_append(session->status, temp);
1057 ret = receive_cmd(session, command->private.sequence_atomic.commands);
1059 resultStatus = DM_ERR_COMMAND_FAILED;
1061 //mo_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1067 _DEBUG_TRACE(" error : %d\n", ret);
1073 static DM_ERROR _receive_atomic_cmd(Session * session, Command * command)
1077 DM_ERROR ret = DM_OK;
1079 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
1080 retvm_if((command) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "command is NULL!!");
1082 int resultStatus = DM_ERR_ACCEPTED_FOR_PROCESSING;
1084 GList *atomic_iter = NULL;
1085 Command *pCommand = NULL;
1086 Status *temp = NULL;
1087 sync_agent_dm_mo_error_e mo_ret = sync_agent_begin_transaction_mo();
1089 for (atomic_iter = command->private.sequence_atomic.commands; atomic_iter != NULL;) {
1090 pCommand = atomic_iter->data;
1092 if (pCommand->type == COMMAND_TYPE_GET) {
1093 ret = create_newstatus(session, DM_ERR_COMMAND_FAILED, pCommand, pCommand->source, pCommand->target, COMMAND_TYPE_GET, &temp);
1097 session->status = g_list_append(session->status, temp);
1099 atomic_iter = g_list_next(atomic_iter);
1100 command->private.sequence_atomic.commands = g_list_remove(command->private.sequence_atomic.commands, pCommand);
1104 ret = receive_cmd(session, command->private.sequence_atomic.commands);
1106 resultStatus = DM_ERR_ATOMIC_FAILED;
1109 if (resultStatus == DM_ERR_ACCEPTED_FOR_PROCESSING) {
1110 mo_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1112 mo_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1113 __rollback_atomic(session, command);
1116 Status *temp_status = NULL;
1117 ret = create_newstatus(session, resultStatus, command, pCommand->source, pCommand->target, COMMAND_TYPE_ATOMIC, &temp_status);
1121 session->status = g_list_append(session->status, temp_status);
1127 _DEBUG_TRACE(" error : %d\n", ret);
1133 static DM_ERROR _receive_alert_status(Session * session, Status * status)
1137 DM_ERROR ret = DM_OK;
1139 retvm_if((status) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "status is NULL!!");
1141 unsigned int code = get_statuscode(status);
1142 if (code >= 400 && code != DM_ERR_REQUIRE_REFRESH) {
1144 //407 Authentication required
1145 //405 command not allowed
1146 //406 optional feature not supported
1147 //500 command failed
1148 //412 Incomplete command
1149 //415 unsupported media type or format
1150 //404 not found ->it have to be considered
1152 //TODO error handling it's error~!!!!!
1155 _DEBUG_TRACE(" end, Error Type : %d\n", ret);
1160 static DM_ERROR _receive_results_status(Session * session, Status * status)
1164 DM_ERROR ret = DM_OK;
1166 retvm_if((status) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "status is NULL!!");
1168 unsigned int code = get_statuscode(status);
1170 //TODO error handling it's error~!!!!!
1172 //407 authentication required
1174 //413 request entity too large
1175 //415 unspported media type or format
1176 //500 command failed
1180 _DEBUG_TRACE(" end, Error Type : %d\n", ret);
1185 static void _free_pending_statuses(GList * pendingStatus)
1189 retm_if((pendingStatus) == NULL, "pendingStatus is NULL!!");
1192 for (iter = pendingStatus; iter != NULL; iter = g_list_next(iter))
1193 __free_pending_status(iter->data);
1195 g_list_free(pendingStatus);
1200 static void __free_pending_status(PendingStatus * pendingStatus)
1204 retm_if((pendingStatus) == NULL, "pendingStatus is NULL!!");
1206 free(pendingStatus);
1207 pendingStatus = NULL;
1212 DM_ERROR create_syncml_session(ProtocolVersion protocolVersion, ProtocolType protocolType, char *server_id, char *client_id, char *pSession_id, char *pSourceUrl, char *pTargetUrl, Session ** pSession)
1216 DM_ERROR ret = DM_OK;
1218 retvm_if((pSourceUrl) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "pSourceUrl is NULL!!");
1219 retvm_if((pTargetUrl) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "pTargetUrl is NULL!!");
1221 *pSession = (Session *) calloc(1, sizeof(Session));
1222 if (*pSession == NULL) {
1223 ret = COMMON_ERR_ALLOC;
1227 (*pSession)->protocolType = protocolType;
1228 (*pSession)->protocolVersion = protocolVersion;
1229 /* (*pSession)->accountId = accountId;*/
1230 if (server_id != NULL)
1231 (*pSession)->pServer_id = strdup(server_id);
1232 (*pSession)->service_engine_id = NO_SERVICE_ENGINE;
1233 (*pSession)->sessionID = strdup(pSession_id);
1234 (*pSession)->jsessionid = NULL;
1236 ret = create_location(pSourceUrl, client_id, &((*pSession)->source));
1240 ret = create_location(pTargetUrl, NULL, &((*pSession)->target));
1244 (*pSession)->msgID = 0;
1245 (*pSession)->cmdID = 1;
1247 (*pSession)->res_chal = NULL;
1248 (*pSession)->req_chal = NULL;
1250 (*pSession)->isHMAC = 0; /*not using hmac */
1251 (*pSession)->reqhmacinfo = (Hmac *) calloc(1, sizeof(Hmac) + 1);
1252 if ((*pSession)->reqhmacinfo == NULL) {
1253 ret = COMMON_ERR_ALLOC;
1256 (*pSession)->resphmacinfo = (Hmac *) calloc(1, sizeof(Hmac) + 1);
1257 if ((*pSession)->resphmacinfo == NULL) {
1258 ret = COMMON_ERR_ALLOC;
1262 (*pSession)->sourceMaxMsgSize = DEFAULT_MAX_MSG_SIZE;
1263 (*pSession)->sourceMaxObjSize = DEFAULT_MAX_OBJ_SIZE;
1265 (*pSession)->targetMaxMsgSize = 0;
1266 (*pSession)->targetMaxObjSize = 0;
1273 if (*pSession != NULL) {
1274 _DEBUG_TRACE("free session");
1275 free_session(*pSession);
1278 _DEBUG_TRACE(" error : %d\n", ret);
1284 void free_session(Session * session)
1288 retm_if((session) == NULL, "session is NULL!!");
1290 if (session->pServer_id != NULL) {
1291 free(session->pServer_id);
1292 session->pServer_id = NULL;
1295 if (session->sessionID != NULL) {
1296 free(session->sessionID);
1297 session->sessionID = NULL;
1300 free_statuses(session->status);
1301 session->status = NULL;
1303 free_statuses(session->tempStatus);
1304 session->status = NULL;
1306 if (session->target != NULL) {
1307 free_location(session->target);
1308 session->target = NULL;
1311 if (session->source != NULL) {
1312 free_location(session->source);
1313 session->source = NULL;
1316 if (session->orgTarget != NULL) {
1317 free_location(session->orgTarget);
1318 session->orgTarget = NULL;
1321 if (session->cred != NULL) {
1322 free_cred(session->cred);
1323 session->cred = NULL;
1326 if (session->res_chal != NULL) {
1327 free_chal(session->res_chal);
1328 session->res_chal = NULL;
1331 if (session->req_chal != NULL) {
1332 free_chal(session->req_chal);
1333 session->req_chal = NULL;
1336 if (session->reqhmacinfo != NULL) {
1337 free_hmac(session->reqhmacinfo);
1338 session->reqhmacinfo = NULL;
1340 if (session->resphmacinfo != NULL) {
1341 free_hmac(session->resphmacinfo);
1342 session->resphmacinfo = NULL;
1345 _free_pending_statuses(session->pendingStatus);
1346 session->pendingStatus = NULL;
1348 if (session->pLargeObjCmd != NULL) {
1349 free_command(session->pLargeObjCmd);
1357 DM_ERROR receive_header(Session * session, SyncHdr * header)
1361 DM_ERROR ret = DM_OK;
1362 Location *pLocation = NULL;
1364 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
1365 retvm_if((header) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "header is NULL!!");
1367 if (session->sessionID != NULL && header->sessionID != NULL) {
1368 if (strcmp(session->sessionID, header->sessionID) != 0) {
1369 ret = COMMON_ERR_GENERIC;
1374 session->lastRecievedMsgID = header->messageID;
1376 if (0 < header->maxmsgsize)
1377 session->targetMaxMsgSize = header->maxmsgsize;
1379 session->targetMaxMsgSize = DEFAULT_SERVER_MAXMSGSIZE;
1381 if (0 < header->maxobjsize)
1382 session->targetMaxObjSize = header->maxobjsize;
1384 if (header->responseURI != NULL) {
1385 if (session->orgTarget == NULL) {
1386 session->orgTarget = session->target;
1387 session->target = NULL;
1390 if (session->target != NULL)
1391 free_location(session->target);
1393 ret = create_location(header->responseURI, get_location_locname(session->orgTarget), &pLocation);
1396 session->target = pLocation;
1398 if (session->target == NULL) {
1399 ret = COMMON_ERR_INTERNAL_NO_MEMORY;
1403 _DEBUG_INFO(" target %s\n", session->target->locURI);
1406 Status *temp = NULL;
1407 DM_ERROR statusData = DM_ERR_UNKNOWN;
1409 if (header->cred != NULL) {
1410 _DEBUG_INFO("header cred ");
1411 //ret = check_server_cred(header->cred, session);
1412 statusData = DM_ERR_AUTH_ACCEPTED;
1417 _DEBUG_INFO("header not cred ");
1421 ret = create_status(statusData, session->cmdID++, session->lastRecievedMsgID, 0, header->source, header->target, NULL, COMMAND_TYPE_HEADER, &temp);
1425 session->status = g_list_append(session->status, temp);
1434 _DEBUG_INFO(" error : %d\n", ret);
1439 DM_ERROR receive_statuses(Session * session, GList * receiveStatus)
1443 DM_ERROR ret = DM_OK;
1445 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
1447 GList *statusItem = receiveStatus;
1448 Status *status = NULL;
1450 Status *req_chal_status = NULL;
1451 GList *header = NULL;
1453 while (statusItem) {
1454 status = statusItem->data;
1456 if (status->cmdRef == 0) {
1457 /*status of SyncHdr */
1458 assert(status->type == COMMAND_TYPE_HEADER);
1459 assert(status->data);
1460 DM_ERROR errorCode = atoi(status->data);
1462 if (errorCode == DM_ERR_AUTH_ACCEPTED || errorCode == DM_OK || errorCode == DM_ERR_UNAUTHORIZED || errorCode == DM_ERR_AUTHENTICATION_REQUIRED) {
1463 //212 || 200 || 401 || 407
1464 //when auth type is AUTH_TYPE_BASIC does not need to send cred in syncHdr in same session
1465 //when auth type is AUTH_TYPE_MD5 the next nonce in Chal MUST used for the digest when the next sync session is started.
1467 Chal *chal = status->chal;
1469 _DEBUG_INFO("exist chal");
1471 //res_chal in status have to be stored in config_tbl because it have to be used next sync session
1472 _DEBUG_INFO("format type :%d\n", chal->format);
1474 /*next session nonce data */
1475 if (chal->nonce_plain != NULL) {
1476 set_client_nextnonce(session->pServer_id, chal->nonce_plain);
1479 /*create next req_chal */
1480 if (chal->type == AUTH_TYPE_MD5) {
1481 _DEBUG_INFO("session have cred md5");
1482 set_client_authtype(session->pServer_id, chal->type);
1483 ret = create_chal(FORMAT_TYPE_BASE64, AUTH_TYPE_MD5, ELEMENT_DEFAULT_CLIENT_NONCE, &pChal);
1486 } else if (chal->type == AUTH_TYPE_HMAC) {
1487 session->isHMAC = 1;
1488 _DEBUG_INFO("session have not cred , using hmac");
1489 set_client_authtype(session->pServer_id, chal->type);
1490 ret = create_chal(FORMAT_TYPE_BASE64, AUTH_TYPE_HMAC, ELEMENT_DEFAULT_CLIENT_NONCE, &pChal);
1495 if (pChal != NULL) {
1497 for (header = session->status; header != NULL; header = g_list_next(header)) {
1498 req_chal_status = (Status *) (header->data);
1499 if (req_chal_status != NULL) {
1500 _DEBUG_TRACE("req_chal_status status type : %d", req_chal_status->type);
1501 if (req_chal_status->type == COMMAND_TYPE_HEADER) {
1502 ((Status *) (req_chal_status))->chal = dup_chal(pChal);
1503 _DEBUG_TRACE("add header chal");
1511 _DEBUG_INFO("chal null");
1514 if (errorCode == DM_ERR_AUTH_ACCEPTED || errorCode == DM_ERR_UNAUTHORIZED || errorCode == DM_ERR_AUTHENTICATION_REQUIRED) {
1515 if (session->cred != NULL) {
1516 free_cred(session->cred);
1517 session->cred = NULL;
1523 if (errorCode == DM_ERR_UNAUTHORIZED) {
1524 ret = DM_ERR_UNAUTHORIZED;
1526 } else if (errorCode == DM_ERR_AUTHENTICATION_REQUIRED) {
1527 ret = DM_ERR_AUTHENTICATION_REQUIRED;
1531 } else if (errorCode == DM_ERR_SERVER_FAILURE) {
1532 ret = DM_ERR_SERVER_FAILURE;
1536 //status except status of SyncHdr
1537 GList *pendingStatusItem = session->pendingStatus;
1538 PendingStatus *pending = NULL;
1539 while (pendingStatusItem) {
1540 pending = pendingStatusItem->data;
1542 if (pending->cmdID == status->cmdRef && pending->msgID == status->msgRef) {
1543 //if status's cmdID and msgID exists in pendigStatus
1545 if (status->type == COMMAND_TYPE_ALERT) {
1546 ret = _receive_alert_status(session, status);
1547 } else if (status->type == COMMAND_TYPE_RESULTS) {
1548 ret = _receive_results_status(session, status);
1551 COMMAND_TYPE_GET, COMMAND_TYPE_ADD, COMMAND_TYPE_REPLACE, COMMAND_TYPE_DELETE
1552 COMMAND_TYPE_COPY, COMMAND_TYPE_EXEC, COMMAND_TYPE_ATOMIC, COMMAND_TYPE_SEQUENCE
1558 session->pendingStatus = g_list_remove(session->pendingStatus, pending);
1561 //if status's cmdID and msgID doesn't exists in pendigStatus
1562 //is it error?? does this can happen??
1564 pendingStatusItem = g_list_next(pendingStatusItem);
1567 statusItem = g_list_next(statusItem);
1576 _DEBUG_INFO(" error, Error Type %d \n", ret);
1581 DM_ERROR receive_cmd(Session * session, GList * receiveCommand)
1585 DM_ERROR ret = DM_OK;
1587 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
1589 GList *commandItem = receiveCommand;
1590 Command *command = NULL;
1592 while (commandItem) {
1593 command = commandItem->data;
1595 switch (command->type) {
1596 case COMMAND_TYPE_ALERT:
1597 ret = _receive_alert_cmd(session, command);
1599 case COMMAND_TYPE_GET:
1600 ret = _receive_get_cmd(session, command);
1602 case COMMAND_TYPE_RESULTS:
1603 ret = _receive_results_cmd(session, command);
1605 case COMMAND_TYPE_ADD:
1606 case COMMAND_TYPE_REPLACE:
1607 case COMMAND_TYPE_DELETE:
1608 case COMMAND_TYPE_COPY:
1609 ret = _receive_changes_cmd(session, command);
1611 case COMMAND_TYPE_EXEC:
1612 ret = _receive_exec_cmd(session, command);
1614 case COMMAND_TYPE_SEQUENCE:
1615 ret = _receice_sequence_cmd(session, command);
1617 case COMMAND_TYPE_ATOMIC:
1618 ret = _receive_atomic_cmd(session, command);
1620 case COMMAND_TYPE_UNKNOWN:
1621 case COMMAND_TYPE_HEADER:
1622 _DEBUG_INFO("not support command");
1628 _DEBUG_INFO("receivce cmd ret : %d", ret);
1629 commandItem = g_list_next(commandItem);
1638 _DEBUG_INFO(" error : %d\n", ret);
1643 DM_ERROR create_prependingstatus(unsigned int msgID, unsigned int cmdID, PendingStatus ** pPendingStatus)
1647 DM_ERROR ret = DM_OK;
1649 *pPendingStatus = (PendingStatus *) calloc(1, sizeof(PendingStatus));
1651 if (*pPendingStatus == NULL) {
1652 ret = COMMON_ERR_ALLOC;
1656 (*pPendingStatus)->msgID = msgID;
1657 (*pPendingStatus)->cmdID = cmdID;
1665 _DEBUG_INFO(" error : %d\n", ret);
1670 DM_ERROR set_session_authcred(Session * session, Cred * cred)
1674 DM_ERROR ret = DM_OK;
1676 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
1677 // retvm_if((cred) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED , "cred is NULL!!");
1679 session->cred = cred;
1686 void reset_cmdid_session(Session * session)
1690 retm_if((session) == NULL, "session is NULL!!");
1697 AuthType __get_Session_AuthType_enum(char *data)
1701 AuthType type = AUTH_TYPE_UNKNOWN;
1703 retvm_if((data) == NULL, AUTH_TYPE_MD5, "data is NULL!!");
1705 if (strcmp(data, ELEMENT_BASIC) == 0) {
1706 type = AUTH_TYPE_BASIC;
1707 } else if (strcmp(data, ELEMENT_DIGEST) == 0) {
1708 type = AUTH_TYPE_MD5;
1709 } else if (strcmp(data, ELEMENT_HMAC) == 0) {
1710 type = AUTH_TYPE_HMAC;
1712 type = AUTH_TYPE_UNKNOWN;
1714 _DEBUG_VERBOSE(" end : [%d] \n", type);
1719 void __set_Session_AuthType_name(AuthType authType, char **authname)
1724 case AUTH_TYPE_BASIC:
1725 (*authname) = strdup(ELEMENT_BASIC);
1728 (*authname) = strdup(ELEMENT_DIGEST);
1730 case AUTH_TYPE_HMAC:
1731 (*authname) = strdup(ELEMENT_HMAC);
1734 (*authname) = strdup(ELEMENT_BASIC);
1744 DM_ERROR get_session_clientauthtype(Session * session, AuthType * authType){
1745 _DEBUG_INFO(" start \n");
1747 DM_ERROR ret = DM_OK;
1750 ret = get_dmacc_authType( session->pServer_id, authType);
1752 (*authType) = AUTH_TYPE_BASIC;
1757 (*authType) = __get_Session_AuthType(data);
1761 _DEBUG_INFO(" end \n");
1764 _DEBUG_INFO(" error end [%d]\n", ret);
1768 DM_ERROR get_session_serverauthtype(Session * session, AuthType* authType){
1769 _DEBUG_INFO(" start \n");
1771 DM_ERROR ret = DM_OK;
1774 ret = get_dmacc_authType( session->pServer_id, authType);
1776 (*authType) = AUTH_TYPE_BASIC;
1781 (*authType) = __get_Session_AuthType(data);
1787 _DEBUG_INFO(" end \n");
1791 _DEBUG_INFO(" error end [%d]\n", ret);
1796 static DM_ERROR __userInteration_operation(Command * command, GList ** response, int *result_status)
1800 DM_ERROR ret = DM_OK;
1802 retvm_if((command) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "command is NULL!!");
1804 CommandAlertPrivate pAlert = command->private.alert;
1805 AlertType type = pAlert.type;
1806 GList *alertItems = pAlert.items;
1809 int size = g_list_length(alertItems);
1811 //GList * responseItems = NULL;
1813 /*char* findValue = NULL; */
1814 /*int isCancel = 0; */
1815 uic_data *pUic_data = (uic_data *) calloc(1, sizeof(uic_data) + 1);
1816 if (pUic_data == NULL) {
1817 _DEBUG_VERBOSE("alloc fail");
1819 return COMMON_ERR_ALLOC;
1821 pUic_data->pUic_option = (uic_option *) calloc(1, sizeof(uic_option) + 1);
1822 if ((pUic_data->pUic_option) == NULL) {
1823 _DEBUG_VERBOSE("alloc fail");
1824 free_uic_value(&pUic_data);
1826 return COMMON_ERR_ALLOC;
1828 pUic_data->res_data = (uic_res_data *) calloc(1, sizeof(uic_res_data) + 1);
1829 //uic_option *uic_value = (uic_option *)calloc(1,sizeof(uic_option));
1830 if ((pUic_data->res_data) == NULL) {
1831 _DEBUG_VERBOSE("alloc fail");
1832 free_uic_value(&pUic_data);
1834 return COMMON_ERR_ALLOC;
1837 case DM_ALERT_DISPLAY:
1838 _DEBUG_VERBOSE("alert display ui");
1839 for (iter = alertItems, i = 0; iter != NULL; iter = g_list_next(iter), ++i) {
1841 if (i == 0 && size != 1) {
1842 /*user interaction option */
1843 _DEBUG_VERBOSE("uic opation : %s", pItem->private.data);
1844 ret = exec_userinteration_option(pItem->private.data, &(pUic_data->pUic_option));
1846 if (pItem->private.data != NULL) {
1847 /*user interaction execute */
1848 _DEBUG_VERBOSE("uic display : %s", pItem->private.data);
1849 pUic_data->display = strdup(pItem->private.data);
1850 ret = ui_display(pUic_data);
1851 *result_status = pUic_data->res_data->status;
1856 case DM_ALERT_CONFIRM_OR_REJECT:
1857 _DEBUG_VERBOSE("alert confirm ui");
1858 _DEBUG_VERBOSE("alert confirm alert item size : %d", size);
1859 for (iter = alertItems, i = 0; iter != NULL; iter = g_list_next(iter), ++i) {
1861 if (i == 0 && size != 1) {
1862 /*user interaction option */
1863 ret = exec_userinteration_option(pItem->private.data, &(pUic_data->pUic_option));
1865 /*user interaction execute */
1866 _DEBUG_VERBOSE("uic display : %s", pItem->private.data);
1867 pUic_data->display = strdup(pItem->private.data);
1868 ret = ui_confirm_or_reject(pUic_data);
1869 *result_status = pUic_data->res_data->status;
1873 case DM_ALERT_TEXT_INPUT:
1874 _DEBUG_VERBOSE("alert input ui");
1875 for (iter = alertItems, i = 0; iter != NULL; iter = g_list_next(iter), ++i) {
1877 if (i == 0 && size != 1) {
1878 /*user interaction option */
1879 /*IT ( A , N, D, T , P , I )
1882 ret = exec_userinteration_option(pItem->private.data, &(pUic_data->pUic_option));
1884 /*user interaction execute */
1885 _DEBUG_VERBOSE("uic display : %s", pItem->private.data);
1886 pUic_data->display = strdup(pItem->private.data);
1887 ret = ui_text_input(pUic_data, &result_data);
1888 *result_status = pUic_data->res_data->status;
1889 if (pUic_data->res_data->status == DM_OK) {
1890 (*response) = g_list_append((*response), result_data);
1892 _DEBUG_VERBOSE("input text null");
1898 case DM_ALERT_SINGLE_CHOICE:{
1899 _DEBUG_VERBOSE("alert single choice ui");
1900 for (iter = alertItems, i = 0; iter != NULL; iter = g_list_next(iter), ++i) {
1902 if (i == 0 && size != 1) {
1903 /*user interaction option */
1904 ret = exec_userinteration_option(pItem->private.data, &(pUic_data->pUic_option));
1906 /*user interaction execute */
1908 _DEBUG_VERBOSE("uic display : %s", pItem->private.data);
1909 pUic_data->display = strdup(pItem->private.data);
1911 GList *iter_end = NULL;
1912 iter_end = g_list_next(iter);
1914 data = strdup(pItem->private.data);
1915 pUic_data->multi_data = g_list_append(pUic_data->multi_data, data);
1917 if (iter_end == NULL) {
1918 ret = ui_single_choice(pUic_data, response);
1919 *result_status = pUic_data->res_data->status;
1927 case DM_ALERT_MULTIPLE_CHOICE:{
1928 _DEBUG_VERBOSE("alert single/multiple choice ui");
1929 for (iter = alertItems, i = 0; iter != NULL; iter = g_list_next(iter), ++i) {
1931 if (i == 0 && size != 1) {
1932 /*user interaction option */
1933 if (pItem->private.data != NULL)
1934 ret = exec_userinteration_option(pItem->private.data, &(pUic_data->pUic_option));
1936 /*user interaction execute */
1938 _DEBUG_VERBOSE("uic display : %s", pItem->private.data);
1939 pUic_data->display = strdup(pItem->private.data);
1941 GList *iter_end = NULL;
1942 iter_end = g_list_next(iter);
1944 data = strdup(pItem->private.data);
1945 pUic_data->multi_data = g_list_append(pUic_data->multi_data, data);
1947 if (iter_end == NULL) {
1948 ret = ui_multiple_choice(pUic_data, response);
1949 *result_status = pUic_data->res_data->status;
1958 case DM_ALERT_SERVER_INITIATED_MGMT:
1959 case DM_ALERT_CLIENT_INITIATED_MGMT:
1960 case DM_ALERT_NEXT_MESSAGE:
1961 case DM_ALERT_SESSION_ABORT:
1962 case DM_ALERT_CLIENT_EVENT:
1963 case DM_ALERT_NO_END_OF_DATA:
1964 case DM_ALERT_GENERIC_ALERT:
1965 _DEBUG_VERBOSE("not user interaction type");
1973 for(iter = responseItems; iter != NULL; iter = g_list_next(iter)){
1975 temp->items = g_list_append(temp->items, pItem);
1978 free_uic_value(&pUic_data);
1980 _DEBUG_VERBOSE(" end\n");
1986 DM_ERROR add_response_hmacinfo(Session ** session, char *temp_hmac)
1989 DM_ERROR ret = DM_OK;
1990 /*x-syncml-hmac: algorithm=MD5, username="156354238", mac=hvMeISwxSVUEofF2jHhQjA== */
1992 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
1993 retvm_if((temp_hmac) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "hmac is NULL!!");
1998 if ((*session)->resphmacinfo == NULL) {
1999 _DEBUG_INFO("hmac response calloc");
2000 (*session)->resphmacinfo = (Hmac *) calloc(1, sizeof(Hmac) + 1);
2001 if ((*session)->resphmacinfo == NULL) {
2002 return COMMON_ERR_ALLOC;
2006 _DEBUG_INFO("temp_hmac : %s", temp_hmac);
2007 start = strstr(temp_hmac, "=");
2008 if (start == NULL) {
2009 _DEBUG_INFO("auth type null");
2010 return COMMON_ERR_INTERNAL_NOT_DEFINED;
2012 _DEBUG_INFO("hmac : %s", start);
2014 end = strstr(temp_hmac, ",");
2016 _DEBUG_INFO("auth type null");
2017 return COMMON_ERR_INTERNAL_NOT_DEFINED;
2019 _DEBUG_INFO("hmac : %s", end);
2021 _set_hmac_value(&((*session)->resphmacinfo->authtype), start + 1, (end - start - 1));
2022 if ((*session)->resphmacinfo->authtype == NULL) {
2023 _DEBUG_INFO("alloc fail");
2025 return COMMON_ERR_ALLOC;
2027 _DEBUG_INFO("auty type : %s", (*session)->resphmacinfo->authtype);
2029 start = strstr(end, "=");
2030 if (start == NULL) {
2031 _DEBUG_INFO("username null");
2032 return COMMON_ERR_INTERNAL_NOT_DEFINED;
2034 _DEBUG_INFO("hmac : %s", start);
2036 end = strstr(start, ",");
2038 _DEBUG_INFO("username null");
2039 return COMMON_ERR_INTERNAL_NOT_DEFINED;
2041 _DEBUG_INFO("hmac : %s", end);
2043 _set_hmac_value(&((*session)->resphmacinfo->username), start + 2, (end - start - 3));
2044 if ((*session)->resphmacinfo->username == NULL) {
2045 _DEBUG_INFO("alloc fail");
2047 return COMMON_ERR_ALLOC;
2049 _DEBUG_INFO("username : %s", (*session)->resphmacinfo->username);
2051 start = strstr(end, "=");
2052 if (start == NULL) {
2053 _DEBUG_INFO("mac null");
2054 return COMMON_ERR_INTERNAL_NOT_DEFINED;
2056 _DEBUG_INFO("hmac : %s", start);
2057 (*session)->resphmacinfo->mac = strdup(start + 1);
2058 _DEBUG_INFO("mac : %s", (*session)->resphmacinfo->mac);
2064 static void _set_hmac_value(char **key, char *value, int size)
2068 retm_if((value) == NULL, "value is NULL!!");
2069 retm_if((size) == 0, "size is NULL!!");
2075 _DEBUG_INFO("key null");
2078 (*key) = (char *)calloc(1, size + 1);
2079 if ((*key) == NULL) {
2084 strncpy((*key), value, size);
2089 /*DM_ERROR process_commands(Command* pCommand, int * resultStatus) {
2091 _DEBUG_TRACE( " start\n");
2093 DM_ERROR ret = DM_OK;
2094 switch (pCommand->type) {
2095 case COMMAND_TYPE_UNKNOWN:
2097 case COMMAND_TYPE_ALERT:
2098 ret = __process_alert(pCommand, resultStatus);
2100 case COMMAND_TYPE_ADD:
2102 ret = __process_add(pCommand, resultStatus);
2103 case COMMAND_TYPE_REPLACE:
2104 ret = __process_replace(pCommand, resultStatus);
2106 case COMMAND_TYPE_DELETE:
2107 ret = __process_delete(pCommand, resultStatus);
2109 case COMMAND_TYPE_EXEC:
2110 ret = __process_exec(pCommand, resultStatus);
2112 case COMMAND_TYPE_SEQUENCE:
2113 ret = __process_sequence(pCommand, resultStatus);
2115 case COMMAND_TYPE_ATOMIC:
2116 ret = __process_atomic(pCommand, resultStatus);
2118 case COMMAND_TYPE_COPY:
2128 _DEBUG_TRACE( " end\n");
2131 _DEBUG_TRACE( " error end : ret %d\n", ret);
2136 static DM_ERROR __rollback_atomic(Session * session, Command * pCommand)
2140 DM_ERROR ret = DM_OK;
2141 retvm_if((session) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "session is NULL!!");
2142 retvm_if((pCommand) == NULL, COMMON_ERR_INTERNAL_NOT_DEFINED, "pCommand is NULL!!");
2144 Command *current_Command = NULL;
2145 /*Status * temp_status = NULL; */
2146 GList *atomic_iter = NULL;
2147 GList *items = NULL;
2148 GList *temp_items = NULL;
2150 sync_agent_dm_mo_error_e mo_ret = sync_agent_begin_transaction_mo();
2151 _DEBUG_VERBOSE("transaction start : %d", mo_ret);
2153 for (atomic_iter = pCommand->private.sequence_atomic.commands; atomic_iter != NULL; atomic_iter = g_list_next(atomic_iter)) {
2154 current_Command = (Command *) atomic_iter->data;
2156 switch (current_Command->type) {
2157 case COMMAND_TYPE_ALERT:
2158 items = current_Command->private.alert.items;
2160 case COMMAND_TYPE_ADD:
2161 case COMMAND_TYPE_REPLACE:
2162 case COMMAND_TYPE_DELETE:
2163 case COMMAND_TYPE_COPY:
2164 items = current_Command->private.change.items;
2166 case COMMAND_TYPE_GET:
2167 items = current_Command->private.access.items;
2168 // delete result status
2170 case COMMAND_TYPE_UNKNOWN:
2171 case COMMAND_TYPE_HEADER:
2172 case COMMAND_TYPE_RESULTS:
2173 case COMMAND_TYPE_EXEC:
2174 case COMMAND_TYPE_SEQUENCE:
2175 case COMMAND_TYPE_ATOMIC:
2176 _DEBUG_VERBOSE("not support command in atomic");
2182 for (temp_items = items; temp_items != NULL; temp_items = g_list_next(temp_items)) {
2183 item = temp_items->data;
2185 ret = set_status_data(session, current_Command, item, DM_ERR_ATOMIC_ROLL_BACK_OK);
2189 _DEBUG_VERBOSE(" end\n");