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.
18 #include "utility/sync_util.h"
20 #include "plugin/mo_plugin.h"
22 #include "data-adapter/common.h"
24 #include "device-manager/mo_tnds_processor.h"
25 #include "device-manager/mo_database_handler.h"
26 #include "device-manager/mo_ddf_parser.h"
27 #include "device-manager/mo_accessor.h"
28 #include "device-manager/mo_accessor_internal.h"
30 #include "utility/fw_time.h"
36 #define EXPORT_API __attribute__ ((visibility("default")))
39 #ifndef SYNC_AGENT_LOG
41 #define LOG_TAG "AF_MO"
46 static int _get_parent_path(const char *mo_pull_path, char **mo_parent_path, char **mo_name);
48 static sync_agent_dm_mo_node_s *_create_default_mo_node(char *mo_full_path);
50 static sync_agent_dm_mo_error_e _recursive_get_Descendant_MO_List(sync_agent_dm_mo_type_e type, const char *mo_path, sync_agent_dm_mo_node_s * parent_node, int *count, sync_agent_dm_mo_get_option_e option);
52 static char *_get_access_type_string(sync_agent_dm_mo_access_type_e access_type);
54 static sync_agent_dm_mo_error_e __set_MO_RunTimeProperty(char **server_id_list, int server_id_list_cnt, sync_agent_dm_mo_node_s * mo_node);
56 static sync_agent_dm_mo_error_e _add_MO_Tree(sync_agent_dm_mo_type_e mo_type, sync_agent_dm_mo_node_s * mo_node, plugin_get_mo_value_cb func_point_get_value, char **server_id_list, int server_id_list_cnt, int server_type);
58 /* static void __print_Tree(sync_agent_dm_mo_node_s * root_ptr, int depth); // to Debugging */
60 static int _update_MO_info(sync_agent_dm_mo_node_s * mo_node, int depth, void **arg);
62 EXPORT_API sync_agent_dm_mo_error_e sync_agent_open_mo()
68 return dm_mo_open("/opt/usr/dbspace/.momanager.db");
71 EXPORT_API sync_agent_dm_mo_error_e sync_agent_close_mo()
80 EXPORT_API sync_agent_dm_mo_error_e sync_agent_construct_mo_table(sync_agent_dm_mo_type_e mo_type, const char *vendar_file, int mo_plugin_id, int server_type)
84 retvm_if(vendar_file == NULL, SYNC_AGENT_DM_MO_FAIL, "vendar_file is NULL !!");
86 _DEBUG_INFO("vender_file = %s", vendar_file);
87 char *root_node_path = strdup(".");
89 sync_agent_dm_mo_node_s *root_node = _create_default_mo_node(root_node_path);
90 if (root_node == NULL) {
91 _DEBUG_INFO("root node null");
92 return SYNC_AGENT_DM_MO_FAIL;
94 sync_agent_dm_mo_error_e err_code = dm_mo_construct_mo_tree_ddf(mo_type, vendar_file, root_node);
95 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
99 plugin_get_mo_value_cb func_point_get_value = NULL;
100 func_point_get_value = plugin_get_function_get_mo_value(mo_plugin_id);
102 plugin_get_server_id_list_cb func_point_get_server_id_list = NULL;
103 func_point_get_server_id_list = plugin_get_function_get_server_id_list(mo_plugin_id);
105 retvm_if(func_point_get_server_id_list == NULL, SYNC_AGENT_DM_MO_FAIL, "cannot get plugin_get_server_id_list_cb !!");
107 char **server_id_list = NULL;
108 int server_id_list_cnt = 0;
109 server_id_list = func_point_get_server_id_list(&server_id_list_cnt);
110 _DEBUG_INFO("server_id_list_cnt = %d", server_id_list_cnt);
112 err_code = sync_agent_begin_transaction_mo();
114 err_code = _add_MO_Tree(mo_type, root_node, func_point_get_value, server_id_list, server_id_list_cnt, server_type);
116 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
117 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
119 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
127 EXPORT_API sync_agent_dm_mo_error_e sync_agent_begin_transaction_mo()
133 return dm_mo_begin_transaction_wraper();
136 EXPORT_API sync_agent_dm_mo_error_e sync_agent_end_transaction_mo(sync_agent_dm_mo_transaction_e transaction)
140 sync_agent_da_transaction_e transation_option;
142 if (transaction == SYNC_AGENT_DM_MO_TRANSACTION_COMMIT) {
143 transation_option = SYNC_AGENT_DA_TRANSACTION_COMMIT;
145 transation_option = SYNC_AGENT_DA_TRANSACTION_ROLLBACK;
150 return dm_mo_end_transaction_wraper(transation_option);
153 sync_agent_dm_mo_error_e dm_create_mo(sync_agent_dm_mo_node_s ** sync_agent_dm_mo_node)
157 *sync_agent_dm_mo_node = (sync_agent_dm_mo_node_s *) calloc(1, sizeof(sync_agent_dm_mo_node_s));
158 if (*sync_agent_dm_mo_node == NULL) {
159 return SYNC_AGENT_DM_MO_FAIL;
161 (*sync_agent_dm_mo_node)->framework_property = (sync_agent_dm_mo_framework_property_s *) calloc(1, sizeof(sync_agent_dm_mo_framework_property_s));
162 if ((*sync_agent_dm_mo_node)->framework_property == NULL) {
163 return SYNC_AGENT_DM_MO_FAIL;
165 (*sync_agent_dm_mo_node)->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
166 if ((*sync_agent_dm_mo_node)->runtime_property == NULL) {
167 return SYNC_AGENT_DM_MO_FAIL;
172 return SYNC_AGENT_DM_MO_SUCCESS;
175 EXPORT_API sync_agent_dm_mo_error_e sync_agent_create_mo_item(sync_agent_dm_mo_node_s ** sync_agent_mo_item)
181 return dm_create_mo(sync_agent_mo_item);
184 EXPORT_API sync_agent_dm_mo_error_e sync_agent_add_mo_item(sync_agent_dm_mo_node_s * sync_agent_mo_item)
188 retvm_if(sync_agent_mo_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
192 return dm_add_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path, sync_agent_mo_item);
195 EXPORT_API sync_agent_dm_mo_error_e sync_agent_update_mo_item(sync_agent_dm_mo_node_s * sync_agent_item)
199 retvm_if(sync_agent_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
203 return dm_update_mo(sync_agent_item->mo_type, sync_agent_item);
206 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_mo_item(const char *mo_path)
210 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
212 sync_agent_dm_mo_type_e mo_type = dm_mo_get_mo_type_wraper(mo_path);
216 return dm_delete_mo(mo_type, mo_path);
219 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_mo_tree_item(const char *mo_path)
223 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
227 return dm_delete_mo_tree(mo_path);
230 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_mo_item(const char *mo_path, sync_agent_dm_mo_node_s ** sync_agent_mo_item)
234 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
238 return dm_get_mo(mo_path, sync_agent_mo_item, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
241 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_mo_items(const char *mo_path, sync_agent_dm_mo_node_s ** sync_agent_mo_item)
245 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
249 return dm_get_mos(mo_path, sync_agent_mo_item, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
252 EXPORT_API sync_agent_dm_mo_error_e sync_agent_query_mo_item(sync_agent_dm_mo_item_s * sync_agent_mo_item, GList ** list)
256 retvm_if(sync_agent_mo_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_item_s is NULL !!");
258 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
260 sync_agent_dm_mo_node_s *mo_node_list = NULL;
262 if (sync_agent_mo_item->interface_type == MO_ITEM_CHILD_MO_VALUE_LIST) {
264 retvm_if(sync_agent_mo_item->mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
266 _DEBUG_INFO("mo full path : %s", sync_agent_mo_item->mo_path);
267 ret = dm_get_child_mo_list(sync_agent_mo_item->mo_type, sync_agent_mo_item->mo_path, &mo_node_list, &count, sync_agent_mo_item->option);
268 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
269 return SYNC_AGENT_DM_MO_FAIL;
271 _DEBUG_INFO("get child mo list count : %d", count);
274 for (i = 0; i < count; ++i) {
275 *list = g_list_append(*list, &(mo_node_list[i]));
278 return SYNC_AGENT_DM_MO_SUCCESS;
280 } else if (sync_agent_mo_item->interface_type == MO_ONLY_DATA_VALUE) {
281 ret = dm_get_mo(sync_agent_mo_item->mo_path, &mo_node_list, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
282 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
283 return SYNC_AGENT_DM_MO_FAIL;
286 *list = g_list_append(*list, mo_node_list);
288 return SYNC_AGENT_DM_MO_SUCCESS;
289 } else if (sync_agent_mo_item->interface_type == MO_ALL_VALUE) {
290 ret = dm_get_mo(sync_agent_mo_item->mo_path, &mo_node_list, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
291 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
292 return SYNC_AGENT_DM_MO_FAIL;
295 *list = g_list_append(*list, mo_node_list);
297 return SYNC_AGENT_DM_MO_SUCCESS;
302 return SYNC_AGENT_DM_MO_FAIL;
305 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_item(sync_agent_dm_mo_node_s * sync_agent_mo_item)
309 if (sync_agent_mo_item != NULL) {
310 dm_free_mo(sync_agent_mo_item, 1);
315 return SYNC_AGENT_DM_MO_SUCCESS;
318 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_item_list(GList * list)
322 retvm_if(list == NULL, SYNC_AGENT_DM_MO_FAIL, "list is NULL !!");
325 count = g_list_length(list);
326 _DEBUG_INFO(" mo list length : %d", count);
327 dm_free_mo(list->data, count);
333 return SYNC_AGENT_DM_MO_FAIL;
336 sync_agent_dm_mo_error_e dm_add_mo(sync_agent_dm_mo_type_e mo_type, const char *mo_full_path, sync_agent_dm_mo_node_s * mo_node)
340 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
341 retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
343 sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
345 _DEBUG_INFO("===============================================");
346 _DEBUG_INFO("sync_agent_dm_mo_type_e : %d", mo_type);
347 _DEBUG_INFO("mo_full_path : %s", mo_full_path);
348 _DEBUG_INFO("mo_value : %s", mo_node->value);
349 _DEBUG_INFO("node type : %d", mo_node->type);
350 _DEBUG_INFO("===============================================");
353 * Get Parent Node from MO DB using by mo_parent_path
355 char *mo_parent_path = NULL;
356 char *mo_name = NULL;
357 int isRootNode = _get_parent_path(mo_full_path, &mo_parent_path, &mo_name);
358 if (isRootNode == -1) {
359 if (mo_parent_path != NULL)
360 free(mo_parent_path);
361 return SYNC_AGENT_DM_MO_FAIL;
365 _DEBUG_INFO("is root node");
367 * Add MO Node to MO DB
369 err = dm_mo_add_node_wraper(SYNC_AGENT_DM_MO_TYPE_NO_TYPE, mo_node);
370 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
371 _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
378 * Add MO Properties to MO DB
380 if (mo_node->framework_property != NULL) {
381 _DEBUG_INFO("add frameowork_property");
382 err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
383 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
384 _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
388 if (mo_node->runtime_property != NULL) {
389 _DEBUG_INFO("add runtime_property");
390 err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
391 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
392 _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
399 return SYNC_AGENT_DM_MO_SUCCESS;
402 _DEBUG_INFO("mo_parent_path : %s", mo_parent_path);
403 _DEBUG_INFO("mo_name : %s", mo_name);
405 sync_agent_dm_mo_node_s *mo_parent_node = NULL;
406 sync_agent_dm_mo_node_s *real_mo_parent_node = NULL;
407 err = dm_get_mos(mo_parent_path, &mo_parent_node, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
408 _DEBUG_INFO("get mo : %d", err);
410 real_mo_parent_node = mo_parent_node;
411 if (real_mo_parent_node == NULL) {
413 * Create Parent MO Node (Default MO Node)
415 _DEBUG_INFO("parent node empty");
416 real_mo_parent_node = _create_default_mo_node(mo_parent_path);
418 err = dm_add_mo(SYNC_AGENT_DM_MO_TYPE_NO_TYPE, mo_parent_path, real_mo_parent_node);
419 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
425 while (real_mo_parent_node != NULL) {
426 _DEBUG_INFO("parent_node id : %d", real_mo_parent_node->id);
427 _DEBUG_INFO("parent_node mo type : %d", real_mo_parent_node->mo_type);
428 _DEBUG_INFO("parent_node server type : %d", real_mo_parent_node->server_type);
429 _DEBUG_INFO("mo server type : %d", mo_node->server_type);
431 if (real_mo_parent_node->server_type == mo_node->server_type) {
432 _DEBUG_INFO("mo server type : %d", mo_node->server_type);
435 _DEBUG_INFO("this node is not parent node");
436 real_mo_parent_node = real_mo_parent_node->next_node;
439 if (real_mo_parent_node == NULL) {
440 real_mo_parent_node = mo_parent_node;
444 mo_node->name = mo_name;
445 mo_node->parent_id = real_mo_parent_node->id;
446 mo_node->mo_type = real_mo_parent_node->mo_type;
448 _DEBUG_INFO("mo_name : %s", mo_node->name);
449 _DEBUG_INFO("mo_parent_id : %d", mo_node->parent_id);
450 _DEBUG_INFO("node type : %d", mo_node->type);
451 _DEBUG_INFO("mo type : %d", mo_node->mo_type);
454 * Add MO Node to MO DB
456 err = dm_mo_add_node_wraper(mo_node->mo_type, mo_node);
457 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
458 _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
459 dm_free_mo(mo_parent_node, 1);
464 * Add MO Properties to MO DB
466 if (mo_node->framework_property != NULL) {
467 _DEBUG_INFO("add frameowork_property %d", mo_node->id);
468 err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
469 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
470 _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
474 if (mo_node->runtime_property != NULL) {
475 _DEBUG_INFO("add runtime_property %d", mo_node->id);
476 err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
477 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
478 _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
482 _DEBUG_INFO("mo_parent_node->id : %d", real_mo_parent_node->id);
483 _DEBUG_INFO("mo_node->id : %d", mo_node->id);
484 _DEBUG_INFO("================================================");
486 dm_free_mo(mo_parent_node, 1);
490 return SYNC_AGENT_DM_MO_SUCCESS;
493 sync_agent_dm_mo_error_e dm_delete_mo(sync_agent_dm_mo_type_e type, const char *mo_full_path)
497 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
499 _DEBUG_INFO("mo_full_path : %s", mo_full_path);
501 sync_agent_dm_mo_node_s *target_node = NULL;
502 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
504 err_code = dm_get_mo(mo_full_path, &target_node, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
505 _DEBUG_INFO("get mo : %d", err_code);
506 if (target_node == NULL) {
507 _DEBUG_INFO("MO is not existed [%s]", mo_full_path);
508 return SYNC_AGENT_DM_MO_SUCCESS;
512 * Delete All Child Nodes(Recursive)
514 if (target_node->type == SYNC_AGENT_DM_MO_NODE_INTERIOR || target_node->type == SYNC_AGENT_DM_MO_NODE_ROOT || target_node->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
516 * Get all right Child Node list
518 sync_agent_dm_mo_node_s *child_node_list = NULL;
519 int child_node_count = 0;
520 err_code = dm_get_child_mo_list(type, mo_full_path, &child_node_list, &child_node_count, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
521 _DEBUG_INFO("get child mo list result : %d", err_code);
522 _DEBUG_INFO("child_node_count : %d", child_node_count);
524 if (child_node_list != NULL) {
526 for (; i < child_node_count; i++) {
527 char *child_node_path = child_node_list[i].full_path;
528 err_code = dm_delete_mo(type, child_node_path);
529 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
530 _DEBUG_ERROR("delete mo tree: [%d]", err_code);
531 dm_free_mo(target_node, 1);
533 dm_free_mo(child_node_list, child_node_count);
535 return SYNC_AGENT_DM_MO_FAIL;
540 dm_free_mo(child_node_list, child_node_count);
542 _DEBUG_INFO("leaf node");
546 * Delete sync_agent_dm_mo_node_s, MO Properties In MO DB using by mo_node_id
548 _DEBUG_INFO("target_node->id : %d", target_node->id);
550 err_code = dm_mo_delete_node_wraper(target_node->id);
551 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
552 _DEBUG_ERROR("Failed to call dm_mo_delete_node_wraper [%d]", err_code);
555 err_code = dm_mo_delete_runtime_property_wraper(target_node->id);
556 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
557 _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err_code);
560 err_code = dm_mo_delete_framework_property_wraper(target_node->id);
561 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
562 _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err_code);
565 dm_free_mo(target_node, 1);
569 return SYNC_AGENT_DM_MO_SUCCESS;
572 sync_agent_dm_mo_error_e dm_delete_mo_tree(const char *mo_path)
576 sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_FAIL;
577 sync_agent_dm_mo_node_s *sync_agent_mo_item = NULL;
578 sync_agent_dm_mo_node_s *mo_parent_node = NULL;
581 err = sync_agent_is_exist_mo(mo_path, &is_exist);
582 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
583 _DEBUG_ERROR("remove dm_acc fail, is existed mo fail");
585 return SYNC_AGENT_DM_MO_FAIL;
589 _DEBUG_ERROR("remove dm_acc fail because dm acc %s not existed", mo_path);
591 return SYNC_AGENT_DM_MO_NOT_EXIST_NODE;
594 err = sync_agent_get_mo_items(mo_path, &sync_agent_mo_item);
595 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
596 _DEBUG_ERROR("remove dm_acc fail, get mo ite fail");
598 if(sync_agent_mo_item != NULL) {
599 err = sync_agent_free_mo_item(sync_agent_mo_item);
600 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
601 _DEBUG_ERROR("free mo tree: [%d]", err);
603 _DEBUG_INFO("free mo success");
608 return SYNC_AGENT_DM_MO_FAIL;
611 if (sync_agent_mo_item->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
614 sync_agent_dm_mo_node_s *iter = NULL;
617 err = dm_delete_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path);
618 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
619 _DEBUG_ERROR("free mo tree: [%d]", err);
622 for (iter = sync_agent_mo_item; iter != NULL; iter = iter->next_node, i++) {
623 _DEBUG_INFO("mo_node id : %d", iter->id);
625 _DEBUG_INFO("prent id : %d ", iter->parent_id);
626 err = dm_mo_delete_node_wraper(iter->parent_id);
627 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
628 _DEBUG_ERROR("delete mo tree: [%d]", err);
632 err = dm_mo_delete_runtime_property_wraper(iter->parent_id);
633 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
634 _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err);
638 err = dm_mo_delete_framework_property_wraper(iter->parent_id);
639 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
640 _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err);
645 } else if (sync_agent_mo_item->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
647 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DMACC, sync_agent_mo_item->full_path);
648 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
649 _DEBUG_ERROR("delete mo tree: [%d]", err);
652 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DEVINFO, sync_agent_mo_item->full_path);
653 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
654 _DEBUG_ERROR("delete mo tree: [%d]", err);
657 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DEVDETAIL, sync_agent_mo_item->full_path);
658 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
659 _DEBUG_ERROR("delete mo tree: [%d]", err);
662 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_FUMO, sync_agent_mo_item->full_path);
663 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
664 _DEBUG_ERROR("delete mo tree: [%d]", err);
667 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_LAWMO, sync_agent_mo_item->full_path);
668 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
669 _DEBUG_ERROR("delete mo tree: [%d]", err);
672 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_SCOMO, sync_agent_mo_item->full_path);
673 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
674 _DEBUG_ERROR("delete mo tree: [%d]", err);
679 /*not root node, first node */
681 err = dm_delete_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path);
682 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
683 _DEBUG_ERROR("delete mo tree: [%d]", err);
687 _DEBUG_INFO("prent id : %d ", sync_agent_mo_item->parent_id);
688 err = dm_mo_get_node_from_id_wraper(sync_agent_mo_item->parent_id, &mo_parent_node);
689 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
690 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err);
697 parent_id = mo_parent_node->parent_id;
699 if (mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_ROOT || mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
701 err = dm_mo_delete_node_wraper(mo_parent_node->id);
702 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
703 _DEBUG_ERROR("delete mo tree: [%d]", err);
707 err = dm_mo_delete_runtime_property_wraper(mo_parent_node->id);
708 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
709 _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err);
713 err = dm_mo_delete_framework_property_wraper(mo_parent_node->id);
714 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
715 _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err);
719 if (mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
720 err = sync_agent_free_mo_item(mo_parent_node);
721 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
722 _DEBUG_ERROR("free mo tree: [%d]", err);
725 _DEBUG_INFO("free mo success");
732 _DEBUG_INFO("first node path : %s", mo_parent_node->full_path);
733 err = dm_delete_mo(mo_parent_node->mo_type, mo_parent_node->full_path);
734 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
735 _DEBUG_ERROR("free mo tree: [%d]", err);
740 err = sync_agent_free_mo_item(mo_parent_node);
741 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
742 _DEBUG_ERROR("free mo tree: [%d]", err);
745 _DEBUG_INFO("free mo success");
748 mo_parent_node = NULL;
750 _DEBUG_INFO("prent id : %d ", parent_id);
751 err = dm_mo_get_node_from_id_wraper(parent_id, &mo_parent_node);
752 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
753 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err);
759 err = sync_agent_free_mo_item(sync_agent_mo_item);
760 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
761 _DEBUG_ERROR("free mo tree: [%d]", err);
764 _DEBUG_INFO("free mo success");
772 err = sync_agent_free_mo_item(sync_agent_mo_item);
773 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
774 _DEBUG_ERROR("free mo tree: [%d]", err);
776 _DEBUG_INFO("free mo success");
779 if(mo_parent_node != NULL) {
780 free(mo_parent_node);
781 mo_parent_node = NULL;
788 sync_agent_dm_mo_error_e dm_update_mo(sync_agent_dm_mo_type_e type, const sync_agent_dm_mo_node_s * mo_node)
792 retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
794 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
796 _DEBUG_INFO("sync_agent_dm_mo_type_e : %d", type);
797 _DEBUG_INFO("node_id : %d", mo_node->id);
798 _DEBUG_INFO("will be updated full_path : %s", mo_node->full_path);
803 err_code = dm_mo_update_node_wraper(type, mo_node->full_path, mo_node);
805 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
806 _DEBUG_ERROR("Failed dm_mo_update_node_wraper() : %d", err_code);
811 * Update Framework property tbl
813 if (mo_node->framework_property != NULL) {
814 err_code = dm_mo_update_framework_property_wraper(mo_node->id, mo_node->framework_property);
815 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
816 _DEBUG_ERROR("Failed dm_mo_update_framework_property_wraper() : %d", err_code);
821 * Update Runtime property tbl
823 if (mo_node->runtime_property != NULL) {
824 err_code = dm_mo_update_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
825 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
826 _DEBUG_ERROR("Failed dm_mo_update_runtime_property_wraper() : %d", err_code);
835 sync_agent_dm_mo_error_e dm_get_child_mo_list(sync_agent_dm_mo_type_e type, const char *mo_path, sync_agent_dm_mo_node_s ** mo_node_list, int *count, sync_agent_dm_mo_get_option_e option)
839 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
841 _DEBUG_INFO("mo_path : %s", mo_path);
843 sync_agent_dm_mo_error_e err_code = dm_mo_get_child_node_wraper(type, mo_path, mo_node_list, count);
844 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
845 _DEBUG_ERROR("Failed to dm_mo_get_child_node_wraper : [%d]", err_code);
850 if (option == SYNC_AGENT_DM_MO_GET_OPTION_NODE) {
852 return SYNC_AGENT_DM_MO_SUCCESS;
856 * todo Set Property to node list
859 for (; i < *count; i++) {
860 err_code = dm_mo_get_framework_property_wraper((*mo_node_list)[i].id, &((*mo_node_list)[i].framework_property));
861 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
862 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
864 err_code = dm_mo_get_runtime_property_wraper((*mo_node_list)[i].id, &((*mo_node_list)[i].runtime_property));
865 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
866 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
872 return SYNC_AGENT_DM_MO_SUCCESS;
875 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_descendant_mo_tree(sync_agent_dm_mo_type_e type, const char *mo_path, sync_agent_dm_mo_node_s ** root_node, int *count, sync_agent_dm_mo_get_option_e option)
879 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
881 sync_agent_dm_mo_error_e err_code = dm_get_mo(mo_path, root_node, option);
882 _DEBUG_INFO("mo_path : %s", mo_path);
883 if(err_code == SYNC_AGENT_DM_MO_FAIL) {
889 err_code = _recursive_get_Descendant_MO_List(type, mo_path, *root_node, count, option);
890 _DEBUG_INFO("get_decendant mo list : %d", err_code);
891 /* __print_Tree(*root_node); */
898 sync_agent_dm_mo_error_e dm_get_mo(const char *mo_path, sync_agent_dm_mo_node_s ** mo_node, sync_agent_dm_mo_get_option_e option)
902 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
904 _DEBUG_INFO("mo_path : %s", mo_path);
906 sync_agent_dm_mo_error_e err_code = dm_mo_get_node_wraper(mo_path, mo_node);
907 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
908 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
909 if( err_code == SYNC_AGENT_DM_MO_FAIL) {
910 if( *mo_node != NULL ) {
911 sync_agent_free_mo_item(*mo_node);
917 if (*mo_node == NULL) {
918 return SYNC_AGENT_DM_MO_FAIL;
921 if (option == SYNC_AGENT_DM_MO_GET_OPTION_ALL) {
922 err_code = dm_mo_get_framework_property_wraper((*mo_node)->id, &((*mo_node)->framework_property));
923 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
924 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
927 _DEBUG_INFO("dm_mo_get_framework_property_wraper success");
929 err_code = dm_mo_get_runtime_property_wraper((*mo_node)->id, &((*mo_node)->runtime_property));
930 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
931 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
934 _DEBUG_INFO("dm_mo_get_runtime_property_wraper success");
945 sync_agent_dm_mo_error_e dm_get_mos(const char *mo_path, sync_agent_dm_mo_node_s ** mo_node, sync_agent_dm_mo_get_option_e option)
949 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
951 _DEBUG_INFO("mo_path : %s", mo_path);
953 sync_agent_dm_mo_error_e err_code = dm_mo_get_nodes_wraper(mo_path, mo_node);
954 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
955 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
959 if (*mo_node == NULL) {
960 return SYNC_AGENT_DM_MO_FAIL;
963 if (option == SYNC_AGENT_DM_MO_GET_OPTION_ALL) {
965 sync_agent_dm_mo_node_s *iter = NULL;
969 for (iter = *mo_node; iter != NULL; iter = iter->next_node, i++) {
970 _DEBUG_INFO("mo_node id : %d", iter->id);
971 err_code = dm_mo_get_framework_property_wraper(iter->id, &(iter->framework_property));
972 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
973 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
976 _DEBUG_INFO("dm_mo_get_framework_property_wraper success");
978 err_code = dm_mo_get_runtime_property_wraper(iter->id, &(iter->runtime_property));
979 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
980 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
983 _DEBUG_INFO("dm_mo_get_runtime_property_wraper success");
995 EXPORT_API sync_agent_dm_mo_error_e sync_agent_is_exist_mo(const char *mo_path, int *is_exist)
999 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
1001 _DEBUG_INFO("mo_path : %s", mo_path);
1003 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1004 err_code = dm_mo_is_exist_node_wraper(mo_path);
1005 _DEBUG_INFO("is exist node : %d", err_code);
1006 if (err_code == SYNC_AGENT_DM_MO_EXIST_NODE) {
1008 } else if (err_code == SYNC_AGENT_DM_MO_NOT_EXIST_NODE) {
1011 _DEBUG_ERROR("dm_mo_is_exist_node_wraper() FAIL !!!");
1014 return SYNC_AGENT_DM_MO_FAIL;
1019 return SYNC_AGENT_DM_MO_SUCCESS;
1022 void dm_free_mo(sync_agent_dm_mo_node_s * mo_node, int count)
1026 _DEBUG_INFO("free mo node start");
1027 if ((mo_node) != NULL && count > 0) {
1029 for (i = 0; i < count; ++i) {
1031 if ((mo_node[i]).name != NULL) {
1032 free((mo_node[i]).name);
1034 if ((mo_node[i]).value != NULL) {
1035 free((mo_node[i]).value);
1037 if ((mo_node[i]).full_path != NULL) {
1038 free((mo_node[i]).full_path);
1040 if ((mo_node[i]).runtime_property != NULL) {
1041 if ((mo_node[i]).runtime_property->acl != NULL) {
1042 free((mo_node[i]).runtime_property->acl);
1044 if ((mo_node[i]).runtime_property->name != NULL) {
1045 free((mo_node[i]).runtime_property->name);
1047 if ((mo_node[i]).runtime_property->size != NULL) {
1048 free((mo_node[i]).runtime_property->size);
1050 if ((mo_node[i]).runtime_property->title != NULL) {
1051 free((mo_node[i]).runtime_property->title);
1053 if ((mo_node[i]).runtime_property->tStamp != NULL) {
1054 free((mo_node[i]).runtime_property->tStamp);
1056 if ((mo_node[i]).runtime_property->type_value != NULL) {
1057 free((mo_node[i]).runtime_property->type_value);
1059 if ((mo_node[i]).runtime_property->verNo != NULL) {
1060 free((mo_node[i]).runtime_property->verNo);
1063 if ((mo_node[i]).framework_property != NULL) {
1064 if ((mo_node[i]).framework_property->defaultValue != NULL) {
1065 free((mo_node[i]).framework_property->defaultValue);
1067 if ((mo_node[i]).framework_property->description != NULL) {
1068 free((mo_node[i]).framework_property->description);
1070 if ((mo_node[i]).framework_property->dfTitle != NULL) {
1071 free((mo_node[i]).framework_property->dfTitle);
1073 if ((mo_node[i]).framework_property->dfType_Value != NULL) {
1074 free((mo_node[i]).framework_property->dfType_Value);
1077 if ((mo_node[i]).child_node_list != NULL) {
1078 dm_free_mo((mo_node[i]).child_node_list, (mo_node[i]).child_node_cnt);
1080 if ((mo_node[i]).next_node != NULL) {
1081 dm_free_mo((mo_node[i]).next_node, 1);
1090 EXPORT_API int sync_agent_traverse_mo_tree_preorder(sync_agent_dm_mo_node_s * root_ptr, sync_agent_mo_worker_cb func_ptr, int depth, int err_stop, void **arg)
1094 retvm_if(root_ptr == NULL, -1, "root_ptr is NULL !!");
1096 _DEBUG_INFO("[%d] mo_node name : %s", depth, root_ptr->name);
1101 ret = func_ptr(root_ptr, depth, arg);
1102 if (ret != -1 && err_stop != 0) {
1108 for (; i < root_ptr->child_node_cnt; i++) {
1109 ret = sync_agent_traverse_mo_tree_preorder(&(root_ptr->child_node_list[i]), func_ptr, depth + 1, err_stop, arg);
1110 if (ret != -1 && err_stop != 0) {
1120 /******************************************* TNDS ******************************************/
1122 EXPORT_API sync_agent_dm_mo_error_e sync_agent_export_tnds_stream(sync_agent_dm_tnds_type_e tnds_type, sync_agent_dm_mo_type_e mo_type, const char *mo_full_path, char **output_stream, unsigned int *byte_size)
1126 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1128 sync_agent_dm_mo_node_s *root_node = NULL;
1130 sync_agent_dm_mo_error_e err;
1132 err = sync_agent_get_descendant_mo_tree(mo_type, mo_full_path, &root_node, &node_count, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
1133 _DEBUG_INFO("get decendant mo list : %d", err);
1135 sync_agent_dm_mo_error_e mo_error = dm_get_tnds_from_db(tnds_type, root_node, output_stream, byte_size);
1136 _DEBUG_INFO("get tnds mo list : %d", mo_error);
1137 dm_free_mo(root_node, 1);
1144 EXPORT_API sync_agent_dm_mo_error_e sync_agent_import_tnds_stream(sync_agent_dm_tnds_action_e tnds_action, sync_agent_dm_tnds_type_e tnds_type, sync_agent_dm_mo_type_e mo_type, const char *mo_full_path, char *input_stream, unsigned int byte_size)
1148 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1152 return dm_insert_tnds_to_db(tnds_action, tnds_type, mo_type, mo_full_path, input_stream, byte_size);
1155 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_all_mo_table()
1159 sync_agent_dm_mo_error_e err_code = sync_agent_begin_transaction_mo();
1161 err_code = dm_mo_delete_all_node_wraper();
1162 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1163 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1167 err_code = dm_mo_delete_all_framework_property_wraper();
1168 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1169 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1173 err_code = dm_mo_delete_all_runtime_property_wraper();
1174 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1175 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1177 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1185 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_mo_type(const char *mo_full_path, sync_agent_dm_mo_type_e * mo_type)
1189 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1191 *mo_type = dm_mo_get_mo_type_wraper(mo_full_path);
1195 return SYNC_AGENT_DM_MO_SUCCESS;
1198 sync_agent_dm_mo_error_e dm_get_acl_value(const char *mo_full_path, sync_agent_dm_mo_node_s ** mo_node)
1202 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1204 sync_agent_dm_mo_node_s *iter = NULL;
1205 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1207 if (!strcmp(mo_full_path, ".")) {
1208 err_code = dm_mo_get_node_wraper(mo_full_path, mo_node);
1211 err_code = dm_mo_get_nodes_wraper(mo_full_path, mo_node);
1214 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1215 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
1216 return SYNC_AGENT_DM_MO_FAIL;
1218 retvm_if(*mo_node == NULL, SYNC_AGENT_DM_MO_NOT_EXIST_NODE, "mo_node is NULL !!");
1221 for (iter = (*mo_node); iter != NULL; iter = iter->next_node) {
1222 _DEBUG_INFO("iter mo count : %d", i++);
1224 err_code = dm_mo_get_runtime_property_wraper(iter->id, &(iter->runtime_property));
1225 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1226 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
1227 return SYNC_AGENT_DM_MO_FAIL;
1230 err_code = dm_mo_get_framework_property_wraper(iter->id, &(iter->framework_property));
1231 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1232 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
1233 return SYNC_AGENT_DM_MO_FAIL;
1236 if (iter->runtime_property != NULL && iter->runtime_property->acl != NULL) {
1237 _DEBUG_INFO("mo node id : %d", iter->id);
1238 _DEBUG_INFO("mo node acl : %s", iter->runtime_property->acl);
1239 _DEBUG_INFO("current node_acl");
1242 sync_agent_dm_mo_node_s *mo_parent_node = NULL;
1244 err_code = dm_mo_get_node_from_id_wraper(iter->parent_id, &mo_parent_node);
1245 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1246 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err_code);
1247 if(mo_parent_node != NULL) {
1248 free(mo_parent_node);
1250 return SYNC_AGENT_DM_MO_FAIL;
1254 while (mo_parent_node != NULL) {
1256 err_code = dm_mo_get_runtime_property_wraper(mo_parent_node->id, &(mo_parent_node->runtime_property));
1257 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1258 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
1261 if (mo_parent_node->runtime_property != NULL && mo_parent_node->runtime_property->acl != NULL) {
1262 _DEBUG_INFO("current node_acl");
1264 iter->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
1265 if (iter->runtime_property == NULL) {
1266 _DEBUG_ERROR("alloc fail");
1268 dm_free_mo(mo_parent_node, 1);
1269 mo_parent_node = NULL;
1271 return SYNC_AGENT_DM_MO_FAIL;
1274 iter->runtime_property->acl = strdup(mo_parent_node->runtime_property->acl);
1275 dm_free_mo(mo_parent_node, 1);
1276 mo_parent_node = NULL;
1279 _DEBUG_INFO("parent node_acl null");
1282 parent_id = mo_parent_node->parent_id;
1284 dm_free_mo(mo_parent_node, 1);
1285 mo_parent_node = NULL;
1286 if (parent_id == -1) {
1287 _DEBUG_INFO("root node get acl");
1291 err_code = dm_mo_get_node_from_id_wraper(parent_id, &mo_parent_node);
1292 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1293 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err_code);
1295 dm_free_mo(mo_parent_node, 1);
1296 mo_parent_node = NULL;
1298 return SYNC_AGENT_DM_MO_FAIL;
1304 return SYNC_AGENT_DM_MO_SUCCESS;
1308 * check_acl = 0 : not permission acl
1309 * check_acl = 1 : not have accesstype
1310 * check_acl = 2 : permission acl
1312 EXPORT_API sync_agent_dm_mo_error_e sync_agent_check_acl_value(const char *mo_full_path, sync_agent_dm_mo_access_type_e access_type, const char *server_id, int *check_acl)
1316 if (mo_full_path == NULL || server_id == NULL || access_type == SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) {
1317 _DEBUG_INFO("mo_full_path == NULL || acl_value == NULL || access_type == SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET\n");
1319 return SYNC_AGENT_DM_MO_FAIL;
1322 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1323 sync_agent_dm_mo_node_s *mo_node = NULL;
1324 sync_agent_dm_mo_node_s *iter = NULL;
1325 char *mo_acl_value = NULL;
1326 int isSearch_value = 0;
1327 int isExist_all = 0;
1328 int server_id_length = 0;
1329 char *ptr_sev_id = NULL;
1332 err_code = dm_get_acl_value(mo_full_path, &mo_node);
1333 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1338 if (mo_node == NULL) {
1339 _DEBUG_INFO("command_str is NULL");
1341 err_code = SYNC_AGENT_DM_MO_FAIL;
1345 /*check accecctype error */
1346 _DEBUG_INFO("check accesstype : %d", access_type);
1348 if (mo_node->framework_property != NULL) {
1349 _DEBUG_INFO("framework accesstype : %d", mo_node->framework_property->accessType);
1351 if ((mo_node->framework_property->accessType != SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) && (mo_node->framework_property->accessType & access_type) != access_type) {
1358 for (iter = mo_node; iter != NULL; iter = iter->next_node) {
1359 _DEBUG_INFO("check mo node acl iter\n");
1360 if (iter->runtime_property == NULL || iter->runtime_property->acl == NULL) {
1361 _DEBUG_INFO("mo_acl_value is NULL\n");
1363 err_code = SYNC_AGENT_DM_MO_SUCCESS;
1367 mo_acl_value = iter->runtime_property->acl;
1369 _DEBUG_INFO("ALC : %s\n", mo_acl_value);
1371 if (isSearch_value == 2) {
1373 _DEBUG_INFO("acl ok \n");
1375 _DEBUG_INFO("mo_acl_value = %s\n", mo_acl_value);
1376 _DEBUG_INFO("access_type = %d\n", access_type);
1378 char *command_str = NULL;
1379 command_str = _get_access_type_string(access_type);
1380 if (command_str == NULL) {
1381 _DEBUG_INFO("command_str is NULL");
1383 err_code = SYNC_AGENT_DM_MO_FAIL;
1387 /* search acl command and server_id */
1388 char *ptr_cmd = strstr(mo_acl_value, command_str);
1389 while (ptr_cmd != NULL) {
1390 char *mo_server_id = NULL;
1392 _DEBUG_INFO("########## Operation Start ###########");
1393 _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd);
1394 ptr_cmd += strlen(command_str);
1396 _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd);
1397 ptr_sev_id = strstr(ptr_cmd, "&");
1399 if (ptr_sev_id != NULL) {
1400 server_id_length = strlen(ptr_cmd) - strlen(ptr_sev_id - 1) + 1;
1401 _DEBUG_INFO("ptr_sev_id = %s\n", ptr_sev_id);
1403 _DEBUG_INFO("ptr_sev_id = %s\n", ptr_cmd);
1404 server_id_length = strlen(ptr_cmd);
1407 _DEBUG_INFO("server_id_length = %d\n", server_id_length);
1408 mo_server_id = (char *)calloc(server_id_length + 1, sizeof(char));
1409 if (mo_server_id == NULL) {
1410 _DEBUG_ERROR("CALLOC failed !!!");
1412 err_code = SYNC_AGENT_DM_MO_FAIL;
1415 memset(mo_server_id, 0, sizeof(char)*(server_id_length + 1));
1416 strncpy(mo_server_id, ptr_cmd, server_id_length);
1417 _DEBUG_INFO("[ mo_server_id = %s ]\n", mo_server_id);
1419 if (strcmp(mo_server_id, server_id) == 0) {
1420 _DEBUG_INFO("====> Search ACL Server_id");
1423 if (mo_server_id != NULL) {
1425 mo_server_id = NULL;
1429 } else if (strcmp(mo_server_id, "*") == 0) {
1430 _DEBUG_INFO("Exist All Format");
1434 /* prepare next value check */
1435 if (ptr_sev_id != NULL) {
1436 ptr_cmd = strstr(ptr_sev_id, command_str);
1441 if (mo_server_id != NULL) {
1443 mo_server_id = NULL;
1450 if (mo_node != NULL)
1451 dm_free_mo(mo_node, 1);
1453 if (isSearch_value == 0) {
1455 if (isExist_all == 1) {
1456 _DEBUG_INFO("##############################>>>>>> Search Value => exist * format !!");
1463 _DEBUG_INFO("##############################>>>>>> Not Search Value ");
1472 _DEBUG_INFO("##############################>>>>>> Search Value !!");
1482 if (mo_node != NULL) {
1483 dm_free_mo(mo_node, 1);
1490 EXPORT_API sync_agent_dm_mo_error_e sync_agent_create_mo_acc_item(sync_agent_dm_acc_info_s ** acc_info)
1494 *acc_info = (sync_agent_dm_acc_info_s *) calloc(1, sizeof(sync_agent_dm_acc_info_s));
1495 if (*acc_info == NULL) {
1496 return SYNC_AGENT_DM_MO_FAIL;
1501 return SYNC_AGENT_DM_MO_SUCCESS;
1504 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_mo_acc_item(sync_agent_dm_mo_acc_item_info_s * sync_agent_mo_acc_info_item, sync_agent_dm_acc_info_s ** acc_info)
1508 sync_agent_dm_mo_error_e mo_error = SYNC_AGENT_DM_MO_SUCCESS;
1510 const char *server_id_string = "ServerID";
1511 const char *acc_type_string = 0;
1513 if (sync_agent_mo_acc_info_item == NULL) {
1514 return SYNC_AGENT_DM_MO_FAIL;
1517 _DEBUG_INFO("get acc info : %d ", sync_agent_mo_acc_info_item->acc_type);
1518 _DEBUG_INFO("get acc info : %s ", sync_agent_mo_acc_info_item->serverid);
1520 switch (sync_agent_mo_acc_info_item->acc_type) {
1521 case DEVICE_MANAGE_ACC_TYPE_SERVER:
1522 acc_type_string = "/ServerAppAuth/";
1524 case DEVICE_MANAGE_ACC_TYPE_CLIENT:
1525 acc_type_string = "/ClientAppAuth/";
1529 /*sync_agent_dm_acc_info_s *acc_info = NULL; */
1530 mo_error = dm_mo_get_acc_info_wraper(sync_agent_mo_acc_info_item->serverid, server_id_string, acc_type_string, acc_info);
1532 if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
1533 _DEBUG_ERROR("Failed to dm_mo_get_acc_info_wraper()");
1537 if (*acc_info != NULL) {
1538 _DEBUG_INFO("auth_name : %s", (*acc_info)->auth_name);
1539 _DEBUG_INFO("auth_secret : %s", (*acc_info)->auth_secret);
1540 _DEBUG_INFO("auth_data : %s", (*acc_info)->auth_data);
1541 _DEBUG_INFO("auth_type : %s", (*acc_info)->auth_type);
1542 _DEBUG_INFO("auth_level : %s", (*acc_info)->auth_level);
1543 _DEBUG_INFO("addr : %s\n", (*acc_info)->addr);
1545 _DEBUG_INFO("\nacc_info is NULL!!\n");
1546 return SYNC_AGENT_DM_MO_FAIL;
1554 EXPORT_API sync_agent_dm_mo_error_e sync_agent_update_mo_acc_item(sync_agent_dm_mo_acc_item_info_s * sync_agent_mo_acc_info_item, sync_agent_dm_acc_info_s * acc_info)
1558 sync_agent_dm_mo_error_e mo_error = SYNC_AGENT_DM_MO_SUCCESS;
1559 const char *server_id_string = "ServerID";
1560 const char *acc_type_string = NULL;
1562 if (sync_agent_mo_acc_info_item == NULL) {
1564 return SYNC_AGENT_DM_MO_FAIL;
1567 switch (sync_agent_mo_acc_info_item->acc_type) {
1568 case DEVICE_MANAGE_ACC_TYPE_SERVER:
1569 acc_type_string = "/ServerAppAuth/";
1571 case DEVICE_MANAGE_ACC_TYPE_CLIENT:
1572 acc_type_string = "/ClientAppAuth/";
1576 mo_error = dm_mo_set_acc_info_wraper(sync_agent_mo_acc_info_item->serverid, server_id_string, acc_type_string, acc_info);
1578 if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
1579 _DEBUG_ERROR("Failed to dm_mo_get_acc_info_wraper()");
1583 if (acc_info != NULL) {
1584 _DEBUG_INFO("\nauth_name : %s", acc_info->auth_name);
1585 _DEBUG_INFO("auth_secret : %s", acc_info->auth_secret);
1586 _DEBUG_INFO("auth_data : %s", acc_info->auth_data);
1587 _DEBUG_INFO("auth_type : %s", acc_info->auth_type);
1588 _DEBUG_INFO("auth_level : %s", acc_info->auth_level);
1589 _DEBUG_INFO("addr : %s", acc_info->addr);
1591 _DEBUG_INFO("\nacc_info is NULL!!\n");
1599 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_acc_item(sync_agent_dm_acc_info_s ** acc_info)
1603 if ((*acc_info) != NULL) {
1604 if ((*acc_info)->addr != NULL) {
1605 free((*acc_info)->addr);
1606 (*acc_info)->addr = NULL;
1608 if ((*acc_info)->auth_data != NULL) {
1609 free((*acc_info)->auth_data);
1610 (*acc_info)->auth_data = NULL;
1612 if ((*acc_info)->auth_level != NULL) {
1613 free((*acc_info)->auth_level);
1614 (*acc_info)->auth_level = NULL;
1616 if ((*acc_info)->auth_name != NULL) {
1617 free((*acc_info)->auth_name);
1618 (*acc_info)->auth_name = NULL;
1620 if ((*acc_info)->auth_secret != NULL) {
1621 free((*acc_info)->auth_secret);
1622 (*acc_info)->auth_secret = NULL;
1624 if ((*acc_info)->auth_type != NULL) {
1625 free((*acc_info)->auth_type);
1626 (*acc_info)->auth_type = NULL;
1633 return SYNC_AGENT_DM_MO_SUCCESS;
1636 EXPORT_API sync_agent_dm_mo_error_e sync_agent_uptodate_mo_table(sync_agent_dm_mo_type_e mo_type, int mo_plugin_id, char *mo_root)
1640 retvm_if(mo_root == NULL, SYNC_AGENT_DM_MO_FAIL, "uptodate mo root NULL !!");
1642 _DEBUG_INFO("mo_type : %d", mo_type);
1644 sync_agent_dm_mo_node_s *root_node = NULL;
1646 sync_agent_dm_mo_error_e err;
1647 err = sync_agent_get_descendant_mo_tree(mo_type, mo_root, &root_node, &count, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
1648 _DEBUG_INFO("get decendant mo list : %d", err);
1650 plugin_get_mo_value_cb func_point_get_value = NULL;
1651 _DEBUG_INFO("PLUGIN ID : %d", mo_plugin_id);
1652 func_point_get_value = plugin_get_function_get_mo_value(mo_plugin_id);
1654 sync_agent_traverse_mo_tree_preorder(root_node, _update_MO_info, 0, 0, (void **)(&func_point_get_value));
1658 return SYNC_AGENT_DM_MO_SUCCESS;
1661 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_serverinfo(sync_agent_dm_server_info_s ** server_info)
1665 sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
1666 const char *server_id_string = "ServerID";
1668 err = dm_mo_get_server_id_list_wraper(server_id_string, server_info);
1669 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
1670 _DEBUG_INFO("get server id list : %d", err);
1674 _DEBUG_INFO("get server id list result : %d", err);
1679 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_serverinfo(sync_agent_dm_server_info_s * server_info)
1683 if (server_info != NULL) {
1684 if (server_info->server_id != NULL) {
1685 free(server_info->server_id);
1686 server_info->server_id = NULL;
1688 if (server_info->next != NULL) {
1689 sync_agent_free_serverinfo(server_info->next);
1690 server_info->next = NULL;
1698 return SYNC_AGENT_DM_MO_SUCCESS;
1701 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_serverid(sync_agent_dm_mo_type_e mo_type, char **server_id)
1705 _DEBUG_INFO("mo_type : %d", mo_type);
1707 const char *server_id_string = "ServerID";
1709 sync_agent_dm_server_info_s *head_ptr = NULL;
1710 dm_mo_get_server_id_list_wraper(server_id_string, &head_ptr);
1712 sync_agent_dm_server_info_s *cursor_ptr = head_ptr;
1714 while (cursor_ptr != NULL) {
1715 _DEBUG_INFO("server_id : %s", cursor_ptr->server_id);
1716 _DEBUG_INFO("server_type : %d", cursor_ptr->server_type);
1718 int result = mo_type & (cursor_ptr->server_type);
1720 if (result == mo_type) {
1721 _DEBUG_INFO("corrected");
1722 *server_id = g_strdup(cursor_ptr->server_id);
1723 sync_agent_free_serverinfo(head_ptr);
1724 return SYNC_AGENT_DM_MO_SUCCESS;
1727 cursor_ptr = cursor_ptr->next;
1730 sync_agent_free_serverinfo(head_ptr);
1733 return SYNC_AGENT_DM_MO_FAIL;
1736 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_root_path(const char *mo_full_path, char **root_path)
1740 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1741 err_code = dm_mo_get_root_path_wraper(mo_full_path, root_path);
1742 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1743 _DEBUG_ERROR("Failed dm_mo_get_root_path_wraper() : [%d]", err_code);
1744 return SYNC_AGENT_DM_MO_FAIL;
1746 _DEBUG_INFO("Successed dm_mo_get_root_path_wraper() : [%s]", *root_path);
1752 return SYNC_AGENT_DM_MO_SUCCESS;
1755 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_server_type(const char *server_id, int *server_type)
1759 retvm_if((server_id) == NULL, SYNC_AGENT_DM_MO_FAIL, "server_id is NULL!!");
1761 _DEBUG_INFO("server_id : %s", server_id);
1762 const char *server_id_string = "ServerID";
1764 sync_agent_dm_server_info_s *head_ptr = NULL;
1765 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1766 err_code = dm_mo_get_server_id_list_wraper(server_id_string, &head_ptr);
1768 if (err_code != SYNC_AGENT_DM_MO_FAIL) {
1769 sync_agent_dm_server_info_s *cursor_ptr = head_ptr;
1770 while (cursor_ptr != NULL) {
1771 if (cursor_ptr->server_id == NULL) {
1773 sync_agent_free_serverinfo(head_ptr);
1774 return SYNC_AGENT_DM_MO_SUCCESS;
1776 _DEBUG_INFO("server_id : %s", cursor_ptr->server_id);
1777 _DEBUG_INFO("server_type : %d", cursor_ptr->server_type);
1779 if (!strcmp(cursor_ptr->server_id, server_id)) {
1780 _DEBUG_INFO("corrected server_id : %s", server_id);
1781 *server_type = cursor_ptr->server_type;
1782 sync_agent_free_serverinfo(head_ptr);
1783 return SYNC_AGENT_DM_MO_SUCCESS;
1785 cursor_ptr = cursor_ptr->next;
1790 sync_agent_free_serverinfo(head_ptr);
1793 return SYNC_AGENT_DM_MO_FAIL;
1798 sync_agent_free_serverinfo(head_ptr);
1801 return SYNC_AGENT_DM_MO_SUCCESS;
1804 EXPORT_API sync_agent_dm_mo_error_e sync_agent_initialize_mo(int mo_plugin_id)
1808 plugin_initialize func_point_initialize = NULL;
1809 func_point_initialize = plugin_get_function_initialize(mo_plugin_id);
1811 if (func_point_initialize != NULL) {
1812 int result = func_point_initialize();
1814 return SYNC_AGENT_DM_MO_FAIL;
1817 return SYNC_AGENT_DM_MO_FAIL;
1822 return SYNC_AGENT_DM_MO_SUCCESS;
1825 /******************************** static function implement **********************************/
1827 int _update_MO_info(sync_agent_dm_mo_node_s * mo_node, int depth, void **arg)
1831 if (mo_node == NULL) {
1832 _DEBUG_TRACE("mo_node is NULL!!");
1836 _DEBUG_TRACE("mo_node->full_path : %s", mo_node->full_path);
1837 _DEBUG_TRACE("mo_node->name : %s", mo_node->name);
1838 _DEBUG_TRACE("mo_node->value : %s", mo_node->value);
1840 plugin_get_mo_value_cb func_point_get_value = (plugin_get_mo_value_cb) (*arg);
1842 if (func_point_get_value != NULL) {
1843 func_point_get_value(mo_node->full_path, mo_node->name, &(mo_node->value));
1844 _DEBUG_TRACE("Be Called func_point_get_value();");
1846 dm_update_mo(mo_node->mo_type, mo_node);
1854 /******************************************************** Impl static function *************************************************************/
1856 static int _get_parent_path(const char *mo_pull_path, char **mo_parent_path, char **mo_name)
1860 int mo_pull_path_len = strlen(mo_pull_path);
1862 char *last_delimit = strrchr(mo_pull_path, DELIMIT);
1867 if (last_delimit == NULL) {
1868 *mo_name = (char *)calloc(mo_pull_path_len + 1, sizeof(char));
1869 if (*mo_name == NULL) {
1870 _DEBUG_ERROR("CALLOC failed !!!");
1873 strncpy(*mo_name, mo_pull_path, mo_pull_path_len);
1877 int name_len = strlen(last_delimit);
1878 int parent_path_len = mo_pull_path_len - name_len;
1880 *mo_parent_path = (char *)calloc(parent_path_len + 1, sizeof(char));
1881 if (*mo_parent_path == NULL) {
1882 _DEBUG_ERROR("CALLOC failed !!!");
1885 *mo_name = (char *)calloc(name_len, sizeof(char));
1886 if (*mo_name == NULL) {
1887 _DEBUG_ERROR("CALLOC failed !!!");
1891 strncpy(*mo_parent_path, mo_pull_path, parent_path_len);
1892 strncpy(*mo_name, last_delimit + 1, name_len);
1899 static sync_agent_dm_mo_node_s *_create_default_mo_node(char *mo_full_path)
1903 sync_agent_dm_mo_node_s *mo_node = (sync_agent_dm_mo_node_s *) calloc(1, sizeof(sync_agent_dm_mo_node_s));
1904 if (mo_node == NULL) {
1905 _DEBUG_ERROR("CALLOC failed !!!");
1909 char *mo_parent_path = NULL;
1910 char *mo_name = NULL;
1911 int ret = _get_parent_path(mo_full_path, &mo_parent_path, &mo_name);
1913 dm_free_mo(mo_node, 1);
1915 if (mo_parent_path != NULL)
1916 free(mo_parent_path);
1921 _DEBUG_TRACE("mo_full_path : %s", mo_full_path);
1922 _DEBUG_TRACE("mo_parent_path : %s", mo_parent_path);
1923 _DEBUG_TRACE("mo_name : %s", mo_name);
1925 /* if (mo_parent_path != NULL) {
1926 free(mo_parent_path);
1929 mo_node->parent_id = -1;
1930 mo_node->name = mo_name;
1931 mo_node->full_path = mo_full_path;
1932 mo_node->value = NULL;
1934 if (mo_parent_path == NULL) {
1935 mo_node->type = SYNC_AGENT_DM_MO_NODE_ROOT;
1936 _DEBUG_TRACE("------------------root node-----------------");
1938 mo_node->type = SYNC_AGENT_DM_MO_NODE_INTERIOR;
1940 mo_node->framework_property = (sync_agent_dm_mo_framework_property_s *) calloc(1, sizeof(sync_agent_dm_mo_framework_property_s));
1941 if (mo_node->framework_property == NULL) {
1942 _DEBUG_ERROR("CALLOC failed !!!");
1943 dm_free_mo(mo_node, 1);
1944 if (mo_parent_path != NULL)
1945 free(mo_parent_path);
1949 mo_node->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
1950 if (mo_node->runtime_property == NULL) {
1951 _DEBUG_ERROR("CALLOC failed !!!");
1952 dm_free_mo(mo_node, 1);
1953 if (mo_parent_path != NULL)
1954 free(mo_parent_path);
1959 if (mo_node->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
1960 mo_node->framework_property->dffFormat = SYNC_AGENT_DM_MO_FORMAT_NODE;
1961 mo_node->framework_property->accessType = SYNC_AGENT_DM_MO_ACCESSTYPE_ADD | SYNC_AGENT_DM_MO_ACCESSTYPE_GET;
1962 mo_node->runtime_property->acl = strdup("Get=*&Add=*");
1963 mo_node->runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_NODE;
1964 mo_node->runtime_property->name = strdup(".");
1965 _DEBUG_TRACE("root node acl :%s , root node format : %d root node name : %s", mo_node->runtime_property->acl, mo_node->runtime_property->format, mo_node->runtime_property->name);
1968 if (mo_parent_path != NULL)
1969 free(mo_parent_path);
1976 static sync_agent_dm_mo_error_e _recursive_get_Descendant_MO_List(sync_agent_dm_mo_type_e type, const char *mo_path, sync_agent_dm_mo_node_s * parent_node, int *acc_count, sync_agent_dm_mo_get_option_e option)
1981 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1982 err_code = dm_get_child_mo_list(type, mo_path, &(parent_node->child_node_list), &count, option);
1983 _DEBUG_TRACE("get child mo list err_code_ : %d", err_code);
1984 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1987 parent_node->child_node_cnt = count;
1988 *acc_count = *acc_count + count;
1989 _DEBUG_TRACE("count : %d", count);
1990 _DEBUG_TRACE("acc count : %d", *acc_count);
1991 _DEBUG_TRACE("MO PAHT : %s", mo_path);
1995 for (; i < count; i++) {
1996 _DEBUG_TRACE("RJW : %s", parent_node->child_node_list[i].full_path);
1997 err_code = _recursive_get_Descendant_MO_List(type, parent_node->child_node_list[i].full_path, &(parent_node->child_node_list[i]), acc_count, option);
1998 _DEBUG_TRACE("err_code : %d", err_code);
1999 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
2004 return SYNC_AGENT_DM_MO_FAIL;
2012 static char *_get_access_type_string(sync_agent_dm_mo_access_type_e access_type)
2016 char *command_str = NULL;
2018 _DEBUG_TRACE("accessType = %d\n", access_type);
2019 switch (access_type) {
2020 case SYNC_AGENT_DM_MO_ACCESSTYPE_ADD:
2021 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_ADD");
2022 command_str = "Add=";
2024 case SYNC_AGENT_DM_MO_ACCESSTYPE_COPY:
2025 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_COPY");
2026 command_str = "Copy=";
2028 case SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE:
2029 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE");
2030 command_str = "Delete=";
2032 case SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC:
2033 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC");
2034 command_str = "Exec=";
2036 case SYNC_AGENT_DM_MO_ACCESSTYPE_GET:
2037 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_GET");
2038 command_str = "Get=";
2040 case SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE:
2041 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE");
2042 command_str = "Replace=";
2045 _DEBUG_TRACE("can not execute logic");
2048 _DEBUG_TRACE("command string = %s\n", command_str);
2055 static sync_agent_dm_mo_error_e __set_MO_RunTimeProperty(char **server_id_list, int server_id_list_cnt, sync_agent_dm_mo_node_s * mo_node)
2059 if (mo_node == NULL || server_id_list == NULL) {
2060 _DEBUG_ERROR("mo_node == 0 || server_id_list == 0\n");
2061 return SYNC_AGENT_DM_MO_FAIL;
2064 sync_agent_dm_mo_framework_property_s *framework_property = mo_node->framework_property;
2065 sync_agent_dm_mo_runtime_property_s *runtime_property = mo_node->runtime_property;
2067 /* set format, type, type value, title property for framework property */
2068 runtime_property->format = framework_property->dffFormat;
2069 runtime_property->type = framework_property->dfType;
2071 _DEBUG_VERBOSE("FP[dffFormat = %d], RT[format = %d]", framework_property->dffFormat, runtime_property->format);
2072 _DEBUG_VERBOSE("FP[dfType = %d], RT[type = %d]", framework_property->dfType, runtime_property->type);
2074 if (framework_property->dfType_Value != NULL) {
2075 runtime_property->type_value = strdup(framework_property->dfType_Value);
2076 _DEBUG_VERBOSE("FP[dfType_Value = %s], RT[type_value = %s]", framework_property->dfType_Value, runtime_property->type_value);
2079 if (framework_property->dfTitle != NULL) {
2080 runtime_property->title = strdup(framework_property->dfTitle);
2081 _DEBUG_VERBOSE("FP[dfTitle = %s], RT[title = %s]", framework_property->dfTitle, runtime_property->title);
2084 /* set name for mo_node */
2085 if (mo_node->name != NULL) {
2086 runtime_property->name = strdup(mo_node->name);
2087 _DEBUG_VERBOSE("mo_name[name = %s], RT[name = %s]", mo_node->name, runtime_property->name);
2090 /* set version No, size */
2091 runtime_property->verNo = strdup("0");
2092 runtime_property->size = 0;
2095 SYNC_AGENT_UTIL_TIME_T current_time;
2096 SYNC_AGENT_UTIL_TIME(¤t_time);
2098 SYNC_AGENT_UTIL_TM *time;
2099 time = SYNC_AGENT_UTIL_LOCALTIME(¤t_time);
2101 _DEBUG_VERBOSE("year = %d, mon = %d, day = %d, hour = %d, min = %d, sec = %d", time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec);
2103 runtime_property->tStamp = g_strdup_printf("%04d%02d%02dT%02d%02d%02dZ", time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec);
2104 _DEBUG_VERBOSE("RT[tStamp = %s]", runtime_property->tStamp);
2107 if (runtime_property->acl != NULL) {
2108 /*aready this is setted runtime property acl */
2110 return SYNC_AGENT_DM_MO_SUCCESS;
2113 int total_acl_size = 0;
2114 if (server_id_list_cnt > 0) {
2117 for (i = 0; i < server_id_list_cnt; i++) {
2118 if (server_id_list[i] == NULL) {
2119 _DEBUG_ERROR("server_id_list[%d] == NULL", i);
2120 return SYNC_AGENT_DM_MO_FAIL;
2122 _DEBUG_VERBOSE("server_id_list[%d] = %s, length = %d", i, server_id_list[i], strlen(server_id_list[i]));
2123 total_acl_size += ((10 * DEVICE_MANAGER_MO_ACCESSTYPE_CNT) + strlen(server_id_list[i]));
2126 char *total_acl_value = (char *)calloc(total_acl_size, sizeof(char));
2127 if (total_acl_value == NULL) {
2128 _DEBUG_ERROR("CALLOC failed !!!");
2129 return SYNC_AGENT_DM_MO_FAIL;
2131 int total_acl_value_idx = 0;
2133 sync_agent_dm_mo_access_type_e access_type = SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET;
2134 char *command_str = NULL;
2136 int temp_acl_value_size = 0;
2137 char *temp_acl_value = NULL;
2140 for (i = 1; i <= DEVICE_MANAGER_MO_ACCESSTYPE_CNT; i++) {
2142 _DEBUG_VERBOSE("framework_property->accessType = %d\n", framework_property->accessType);
2143 if (framework_property->accessType != SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) {
2145 access_type = framework_property->accessType & (mul);
2146 _DEBUG_VERBOSE("accessType = %d\n", access_type);
2147 command_str = _get_access_type_string(access_type);
2149 if (command_str != NULL) {
2150 for (j = 0; j < server_id_list_cnt; j++) {
2152 _DEBUG_VERBOSE("server_id_list[%d] = %s", j, server_id_list[j]);
2153 if (i == DEVICE_MANAGER_MO_ACCESSTYPE_CNT && j == server_id_list_cnt - 1) {
2154 temp_acl_value = g_strdup_printf("%s%s", command_str, server_id_list[j]);
2156 temp_acl_value = g_strdup_printf("%s%s&", command_str, server_id_list[j]);
2159 temp_acl_value_size = strlen(temp_acl_value);
2161 _DEBUG_VERBOSE("temp_acl_value = %s\n", temp_acl_value);
2162 memcpy(total_acl_value + total_acl_value_idx, temp_acl_value, temp_acl_value_size);
2163 total_acl_value_idx += temp_acl_value_size;
2173 _DEBUG_VERBOSE("total_acl_value = %s\n", total_acl_value);
2174 runtime_property->acl = total_acl_value;
2179 return SYNC_AGENT_DM_MO_SUCCESS;
2182 static sync_agent_dm_mo_error_e _add_MO_Tree(sync_agent_dm_mo_type_e mo_type, sync_agent_dm_mo_node_s * mo_node, plugin_get_mo_value_cb func_point_get_value, char **server_id_list, int server_id_list_cnt, int server_type)
2186 sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
2188 if (mo_node == NULL) {
2189 return SYNC_AGENT_DM_MO_FAIL;
2192 _DEBUG_TRACE("[%s] [%s] [%d] [%d]", mo_node->name, mo_node->full_path, mo_node->type, mo_node->child_node_cnt);
2193 _DEBUG_TRACE("[%d] [%s] [%d] [%d] [%d] [%s] [%d]", mo_node->framework_property->accessType, mo_node->framework_property->description, mo_node->framework_property->dffFormat, mo_node->framework_property->occurrence,
2194 mo_node->framework_property->scope, mo_node->framework_property->dfTitle, mo_node->framework_property->dfType);
2195 _DEBUG_TRACE("================================================================================");
2198 * Setting acl of RuntimeProperty in PlugIn
2202 * Set MO Value from PlugIn
2204 if (func_point_get_value != NULL) {
2205 func_point_get_value(mo_node->full_path, mo_node->name, &(mo_node->value));
2206 _DEBUG_TRACE("mo value [%s] ", mo_node->value);
2209 mo_node->server_type = server_type;
2210 err = dm_mo_add_node_wraper(mo_type, mo_node);
2211 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2212 _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
2215 err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
2216 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2217 _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
2221 _DEBUG_TRACE("set_mo_run Start");
2222 err = __set_MO_RunTimeProperty(server_id_list, server_id_list_cnt, mo_node);
2223 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2224 _DEBUG_ERROR("Failed __set_MO_RunTimeProperty() : [%d]", err);
2228 _DEBUG_TRACE("set_mo_run ENd");
2229 err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
2230 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2231 _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
2235 sync_agent_dm_mo_node_s *pCursor = mo_node->child_node_list;
2236 while (pCursor != NULL) {
2237 pCursor->parent_id = mo_node->id;
2239 err = _add_MO_Tree(mo_type, pCursor, func_point_get_value, server_id_list, server_id_list_cnt, server_type);
2240 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2244 pCursor = pCursor->next_node;
2253 static void __print_Tree(sync_agent_dm_mo_node_s * root_ptr, int depth)
2255 if (root_ptr == NULL) {
2259 // for ( ; i < depth; i++) {
2260 // _DEBUG_INFO("\t");
2262 _DEBUG_INFO("[%s] [%s] [%d] [%d]", root_ptr->name, root_ptr->full_path, root_ptr->type, root_ptr->child_node_cnt);
2263 _DEBUG_INFO("[%d] [%s] [%d] [%d] [%d] [%s] [%d]", root_ptr->framework_property->accessType, root_ptr->framework_property->description, root_ptr->framework_property->dffFormat, root_ptr->framework_property->occurrence, root_ptr->framework_property->scope, root_ptr->framework_property->dfTitle, root_ptr->framework_property->dfType);
2264 _DEBUG_INFO("================================================================================");
2266 sync_agent_dm_mo_node_s *pCursor = root_ptr->child_node_list;
2267 while (pCursor != NULL) {
2268 __print_Tree(pCursor, depth + 1);
2269 pCursor = pCursor->next_node;