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"
35 #include <tzplatform_config.h>
38 #define EXPORT_API __attribute__ ((visibility("default")))
41 #ifndef SYNC_AGENT_LOG
43 #define LOG_TAG "AF_MO"
48 static int _get_parent_path(const char *mo_pull_path, char **mo_parent_path, char **mo_name);
50 static sync_agent_dm_mo_node_s *_create_default_mo_node(char *mo_full_path);
52 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);
54 static char *_get_access_type_string(sync_agent_dm_mo_access_type_e access_type);
56 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);
58 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);
60 /* static void __print_Tree(sync_agent_dm_mo_node_s * root_ptr, int depth); // to Debugging */
62 static int _update_MO_info(sync_agent_dm_mo_node_s * mo_node, int depth, void **arg);
64 EXPORT_API sync_agent_dm_mo_error_e sync_agent_open_mo()
70 return dm_mo_open((char*)tzplatform_mkpath(TZ_USER_DB,".momanager.db"));
73 EXPORT_API sync_agent_dm_mo_error_e sync_agent_close_mo()
82 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)
86 retvm_if(vendar_file == NULL, SYNC_AGENT_DM_MO_FAIL, "vendar_file is NULL !!");
88 _DEBUG_INFO("vender_file = %s", vendar_file);
89 char *root_node_path = strdup(".");
91 sync_agent_dm_mo_node_s *root_node = _create_default_mo_node(root_node_path);
92 if (root_node == NULL) {
93 _DEBUG_INFO("root node null");
94 return SYNC_AGENT_DM_MO_FAIL;
96 sync_agent_dm_mo_error_e err_code = dm_mo_construct_mo_tree_ddf(mo_type, vendar_file, root_node);
97 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
101 plugin_get_mo_value_cb func_point_get_value = NULL;
102 func_point_get_value = plugin_get_function_get_mo_value(mo_plugin_id);
104 plugin_get_server_id_list_cb func_point_get_server_id_list = NULL;
105 func_point_get_server_id_list = plugin_get_function_get_server_id_list(mo_plugin_id);
107 retvm_if(func_point_get_server_id_list == NULL, SYNC_AGENT_DM_MO_FAIL, "cannot get plugin_get_server_id_list_cb !!");
109 char **server_id_list = NULL;
110 int server_id_list_cnt = 0;
111 server_id_list = func_point_get_server_id_list(&server_id_list_cnt);
112 _DEBUG_INFO("server_id_list_cnt = %d", server_id_list_cnt);
114 err_code = sync_agent_begin_transaction_mo();
116 err_code = _add_MO_Tree(mo_type, root_node, func_point_get_value, server_id_list, server_id_list_cnt, server_type);
118 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
119 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
121 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
129 EXPORT_API sync_agent_dm_mo_error_e sync_agent_begin_transaction_mo()
135 return dm_mo_begin_transaction_wraper();
138 EXPORT_API sync_agent_dm_mo_error_e sync_agent_end_transaction_mo(sync_agent_dm_mo_transaction_e transaction)
142 sync_agent_da_transaction_e transation_option;
144 if (transaction == SYNC_AGENT_DM_MO_TRANSACTION_COMMIT) {
145 transation_option = SYNC_AGENT_DA_TRANSACTION_COMMIT;
147 transation_option = SYNC_AGENT_DA_TRANSACTION_ROLLBACK;
152 return dm_mo_end_transaction_wraper(transation_option);
155 sync_agent_dm_mo_error_e dm_create_mo(sync_agent_dm_mo_node_s ** sync_agent_dm_mo_node)
159 *sync_agent_dm_mo_node = (sync_agent_dm_mo_node_s *) calloc(1, sizeof(sync_agent_dm_mo_node_s));
160 if (*sync_agent_dm_mo_node == NULL) {
161 return SYNC_AGENT_DM_MO_FAIL;
163 (*sync_agent_dm_mo_node)->framework_property = (sync_agent_dm_mo_framework_property_s *) calloc(1, sizeof(sync_agent_dm_mo_framework_property_s));
164 if ((*sync_agent_dm_mo_node)->framework_property == NULL) {
165 return SYNC_AGENT_DM_MO_FAIL;
167 (*sync_agent_dm_mo_node)->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
168 if ((*sync_agent_dm_mo_node)->runtime_property == NULL) {
169 return SYNC_AGENT_DM_MO_FAIL;
174 return SYNC_AGENT_DM_MO_SUCCESS;
177 EXPORT_API sync_agent_dm_mo_error_e sync_agent_create_mo_item(sync_agent_dm_mo_node_s ** sync_agent_mo_item)
183 return dm_create_mo(sync_agent_mo_item);
186 EXPORT_API sync_agent_dm_mo_error_e sync_agent_add_mo_item(sync_agent_dm_mo_node_s * sync_agent_mo_item)
190 retvm_if(sync_agent_mo_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
194 return dm_add_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path, sync_agent_mo_item);
197 EXPORT_API sync_agent_dm_mo_error_e sync_agent_update_mo_item(sync_agent_dm_mo_node_s * sync_agent_item)
201 retvm_if(sync_agent_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
205 return dm_update_mo(sync_agent_item->mo_type, sync_agent_item);
208 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_mo_item(const char *mo_path)
212 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
214 sync_agent_dm_mo_type_e mo_type = dm_mo_get_mo_type_wraper(mo_path);
218 return dm_delete_mo(mo_type, mo_path);
221 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_mo_tree_item(const char *mo_path)
225 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
229 return dm_delete_mo_tree(mo_path);
232 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)
236 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
240 return dm_get_mo(mo_path, sync_agent_mo_item, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
243 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)
247 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
251 return dm_get_mos(mo_path, sync_agent_mo_item, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
254 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)
258 retvm_if(sync_agent_mo_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_item_s is NULL !!");
260 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
262 sync_agent_dm_mo_node_s *mo_node_list = NULL;
264 if (sync_agent_mo_item->interface_type == MO_ITEM_CHILD_MO_VALUE_LIST) {
266 retvm_if(sync_agent_mo_item->mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
268 _DEBUG_INFO("mo full path : %s", sync_agent_mo_item->mo_path);
269 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);
270 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
271 return SYNC_AGENT_DM_MO_FAIL;
273 _DEBUG_INFO("get child mo list count : %d", count);
276 for (i = 0; i < count; ++i) {
277 *list = g_list_append(*list, &(mo_node_list[i]));
280 return SYNC_AGENT_DM_MO_SUCCESS;
282 } else if (sync_agent_mo_item->interface_type == MO_ONLY_DATA_VALUE) {
283 ret = dm_get_mo(sync_agent_mo_item->mo_path, &mo_node_list, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
284 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
285 return SYNC_AGENT_DM_MO_FAIL;
288 *list = g_list_append(*list, mo_node_list);
290 return SYNC_AGENT_DM_MO_SUCCESS;
291 } else if (sync_agent_mo_item->interface_type == MO_ALL_VALUE) {
292 ret = dm_get_mo(sync_agent_mo_item->mo_path, &mo_node_list, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
293 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
294 return SYNC_AGENT_DM_MO_FAIL;
297 *list = g_list_append(*list, mo_node_list);
299 return SYNC_AGENT_DM_MO_SUCCESS;
304 return SYNC_AGENT_DM_MO_FAIL;
307 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_item(sync_agent_dm_mo_node_s * sync_agent_mo_item)
311 if (sync_agent_mo_item != NULL) {
312 dm_free_mo(sync_agent_mo_item, 1);
317 return SYNC_AGENT_DM_MO_SUCCESS;
320 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_item_list(GList * list)
324 retvm_if(list == NULL, SYNC_AGENT_DM_MO_FAIL, "list is NULL !!");
327 count = g_list_length(list);
328 _DEBUG_INFO(" mo list length : %d", count);
329 dm_free_mo(list->data, count);
335 return SYNC_AGENT_DM_MO_FAIL;
338 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)
342 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
343 retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
345 sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
347 _DEBUG_INFO("===============================================");
348 _DEBUG_INFO("sync_agent_dm_mo_type_e : %d", mo_type);
349 _DEBUG_INFO("mo_full_path : %s", mo_full_path);
350 _DEBUG_INFO("mo_value : %s", mo_node->value);
351 _DEBUG_INFO("node type : %d", mo_node->type);
352 _DEBUG_INFO("===============================================");
355 * Get Parent Node from MO DB using by mo_parent_path
357 char *mo_parent_path = NULL;
358 char *mo_name = NULL;
359 int isRootNode = _get_parent_path(mo_full_path, &mo_parent_path, &mo_name);
360 if (isRootNode == -1) {
361 if (mo_parent_path != NULL)
362 free(mo_parent_path);
363 return SYNC_AGENT_DM_MO_FAIL;
367 _DEBUG_INFO("is root node");
369 * Add MO Node to MO DB
371 err = dm_mo_add_node_wraper(SYNC_AGENT_DM_MO_TYPE_NO_TYPE, mo_node);
372 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
373 _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
380 * Add MO Properties to MO DB
382 if (mo_node->framework_property != NULL) {
383 _DEBUG_INFO("add frameowork_property");
384 err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
385 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
386 _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
390 if (mo_node->runtime_property != NULL) {
391 _DEBUG_INFO("add runtime_property");
392 err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
393 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
394 _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
401 return SYNC_AGENT_DM_MO_SUCCESS;
404 _DEBUG_INFO("mo_parent_path : %s", mo_parent_path);
405 _DEBUG_INFO("mo_name : %s", mo_name);
407 sync_agent_dm_mo_node_s *mo_parent_node = NULL;
408 sync_agent_dm_mo_node_s *real_mo_parent_node = NULL;
409 err = dm_get_mos(mo_parent_path, &mo_parent_node, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
410 _DEBUG_INFO("get mo : %d", err);
412 real_mo_parent_node = mo_parent_node;
413 if (real_mo_parent_node == NULL) {
415 * Create Parent MO Node (Default MO Node)
417 _DEBUG_INFO("parent node empty");
418 real_mo_parent_node = _create_default_mo_node(mo_parent_path);
420 err = dm_add_mo(SYNC_AGENT_DM_MO_TYPE_NO_TYPE, mo_parent_path, real_mo_parent_node);
421 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
427 while (real_mo_parent_node != NULL) {
428 _DEBUG_INFO("parent_node id : %d", real_mo_parent_node->id);
429 _DEBUG_INFO("parent_node mo type : %d", real_mo_parent_node->mo_type);
430 _DEBUG_INFO("parent_node server type : %d", real_mo_parent_node->server_type);
431 _DEBUG_INFO("mo server type : %d", mo_node->server_type);
433 if (real_mo_parent_node->server_type == mo_node->server_type) {
434 _DEBUG_INFO("mo server type : %d", mo_node->server_type);
437 _DEBUG_INFO("this node is not parent node");
438 real_mo_parent_node = real_mo_parent_node->next_node;
441 if (real_mo_parent_node == NULL) {
442 real_mo_parent_node = mo_parent_node;
446 mo_node->name = mo_name;
447 mo_node->parent_id = real_mo_parent_node->id;
448 mo_node->mo_type = real_mo_parent_node->mo_type;
450 _DEBUG_INFO("mo_name : %s", mo_node->name);
451 _DEBUG_INFO("mo_parent_id : %d", mo_node->parent_id);
452 _DEBUG_INFO("node type : %d", mo_node->type);
453 _DEBUG_INFO("mo type : %d", mo_node->mo_type);
456 * Add MO Node to MO DB
458 err = dm_mo_add_node_wraper(mo_node->mo_type, mo_node);
459 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
460 _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
461 dm_free_mo(mo_parent_node, 1);
466 * Add MO Properties to MO DB
468 if (mo_node->framework_property != NULL) {
469 _DEBUG_INFO("add frameowork_property %d", mo_node->id);
470 err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
471 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
472 _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
476 if (mo_node->runtime_property != NULL) {
477 _DEBUG_INFO("add runtime_property %d", mo_node->id);
478 err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
479 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
480 _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
484 _DEBUG_INFO("mo_parent_node->id : %d", real_mo_parent_node->id);
485 _DEBUG_INFO("mo_node->id : %d", mo_node->id);
486 _DEBUG_INFO("================================================");
488 dm_free_mo(mo_parent_node, 1);
492 return SYNC_AGENT_DM_MO_SUCCESS;
495 sync_agent_dm_mo_error_e dm_delete_mo(sync_agent_dm_mo_type_e type, const char *mo_full_path)
499 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
501 _DEBUG_INFO("mo_full_path : %s", mo_full_path);
503 sync_agent_dm_mo_node_s *target_node = NULL;
504 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
506 err_code = dm_get_mo(mo_full_path, &target_node, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
507 _DEBUG_INFO("get mo : %d", err_code);
508 if (target_node == NULL) {
509 _DEBUG_INFO("MO is not existed [%s]", mo_full_path);
510 return SYNC_AGENT_DM_MO_SUCCESS;
514 * Delete All Child Nodes(Recursive)
516 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) {
518 * Get all right Child Node list
520 sync_agent_dm_mo_node_s *child_node_list = NULL;
521 int child_node_count = 0;
522 err_code = dm_get_child_mo_list(type, mo_full_path, &child_node_list, &child_node_count, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
523 _DEBUG_INFO("get child mo list result : %d", err_code);
524 _DEBUG_INFO("child_node_count : %d", child_node_count);
526 if (child_node_list != NULL) {
528 for (; i < child_node_count; i++) {
529 char *child_node_path = child_node_list[i].full_path;
530 err_code = dm_delete_mo(type, child_node_path);
531 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
532 _DEBUG_ERROR("delete mo tree: [%d]", err_code);
533 dm_free_mo(target_node, 1);
535 dm_free_mo(child_node_list, child_node_count);
537 return SYNC_AGENT_DM_MO_FAIL;
542 dm_free_mo(child_node_list, child_node_count);
544 _DEBUG_INFO("leaf node");
548 * Delete sync_agent_dm_mo_node_s, MO Properties In MO DB using by mo_node_id
550 _DEBUG_INFO("target_node->id : %d", target_node->id);
552 err_code = dm_mo_delete_node_wraper(target_node->id);
553 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
554 _DEBUG_ERROR("Failed to call dm_mo_delete_node_wraper [%d]", err_code);
557 err_code = dm_mo_delete_runtime_property_wraper(target_node->id);
558 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
559 _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err_code);
562 err_code = dm_mo_delete_framework_property_wraper(target_node->id);
563 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
564 _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err_code);
567 dm_free_mo(target_node, 1);
571 return SYNC_AGENT_DM_MO_SUCCESS;
574 sync_agent_dm_mo_error_e dm_delete_mo_tree(const char *mo_path)
578 sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_FAIL;
579 sync_agent_dm_mo_node_s *sync_agent_mo_item = NULL;
580 sync_agent_dm_mo_node_s *mo_parent_node = NULL;
583 err = sync_agent_is_exist_mo(mo_path, &is_exist);
584 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
585 _DEBUG_ERROR("remove dm_acc fail, is existed mo fail");
587 return SYNC_AGENT_DM_MO_FAIL;
591 _DEBUG_ERROR("remove dm_acc fail because dm acc %s not existed", mo_path);
593 return SYNC_AGENT_DM_MO_NOT_EXIST_NODE;
596 err = sync_agent_get_mo_items(mo_path, &sync_agent_mo_item);
597 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
598 _DEBUG_ERROR("remove dm_acc fail, get mo ite fail");
600 if(sync_agent_mo_item != NULL) {
601 err = sync_agent_free_mo_item(sync_agent_mo_item);
602 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
603 _DEBUG_ERROR("free mo tree: [%d]", err);
605 _DEBUG_INFO("free mo success");
610 return SYNC_AGENT_DM_MO_FAIL;
613 if (sync_agent_mo_item->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
616 sync_agent_dm_mo_node_s *iter = NULL;
619 err = dm_delete_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path);
620 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
621 _DEBUG_ERROR("free mo tree: [%d]", err);
624 for (iter = sync_agent_mo_item; iter != NULL; iter = iter->next_node, i++) {
625 _DEBUG_INFO("mo_node id : %d", iter->id);
627 _DEBUG_INFO("prent id : %d ", iter->parent_id);
628 err = dm_mo_delete_node_wraper(iter->parent_id);
629 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
630 _DEBUG_ERROR("delete mo tree: [%d]", err);
634 err = dm_mo_delete_runtime_property_wraper(iter->parent_id);
635 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
636 _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err);
640 err = dm_mo_delete_framework_property_wraper(iter->parent_id);
641 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
642 _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err);
647 } else if (sync_agent_mo_item->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
649 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DMACC, sync_agent_mo_item->full_path);
650 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
651 _DEBUG_ERROR("delete mo tree: [%d]", err);
654 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DEVINFO, sync_agent_mo_item->full_path);
655 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
656 _DEBUG_ERROR("delete mo tree: [%d]", err);
659 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DEVDETAIL, sync_agent_mo_item->full_path);
660 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
661 _DEBUG_ERROR("delete mo tree: [%d]", err);
664 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_FUMO, sync_agent_mo_item->full_path);
665 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
666 _DEBUG_ERROR("delete mo tree: [%d]", err);
669 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_LAWMO, sync_agent_mo_item->full_path);
670 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
671 _DEBUG_ERROR("delete mo tree: [%d]", err);
674 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_SCOMO, sync_agent_mo_item->full_path);
675 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
676 _DEBUG_ERROR("delete mo tree: [%d]", err);
681 /*not root node, first node */
683 err = dm_delete_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path);
684 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
685 _DEBUG_ERROR("delete mo tree: [%d]", err);
689 _DEBUG_INFO("prent id : %d ", sync_agent_mo_item->parent_id);
690 err = dm_mo_get_node_from_id_wraper(sync_agent_mo_item->parent_id, &mo_parent_node);
691 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
692 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err);
699 parent_id = mo_parent_node->parent_id;
701 if (mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_ROOT || mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
703 err = dm_mo_delete_node_wraper(mo_parent_node->id);
704 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
705 _DEBUG_ERROR("delete mo tree: [%d]", err);
709 err = dm_mo_delete_runtime_property_wraper(mo_parent_node->id);
710 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
711 _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err);
715 err = dm_mo_delete_framework_property_wraper(mo_parent_node->id);
716 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
717 _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err);
721 if (mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
722 err = sync_agent_free_mo_item(mo_parent_node);
723 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
724 _DEBUG_ERROR("free mo tree: [%d]", err);
727 _DEBUG_INFO("free mo success");
734 _DEBUG_INFO("first node path : %s", mo_parent_node->full_path);
735 err = dm_delete_mo(mo_parent_node->mo_type, mo_parent_node->full_path);
736 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
737 _DEBUG_ERROR("free mo tree: [%d]", err);
742 err = sync_agent_free_mo_item(mo_parent_node);
743 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
744 _DEBUG_ERROR("free mo tree: [%d]", err);
747 _DEBUG_INFO("free mo success");
750 mo_parent_node = NULL;
752 _DEBUG_INFO("prent id : %d ", parent_id);
753 err = dm_mo_get_node_from_id_wraper(parent_id, &mo_parent_node);
754 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
755 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err);
761 err = sync_agent_free_mo_item(sync_agent_mo_item);
762 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
763 _DEBUG_ERROR("free mo tree: [%d]", err);
766 _DEBUG_INFO("free mo success");
774 err = sync_agent_free_mo_item(sync_agent_mo_item);
775 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
776 _DEBUG_ERROR("free mo tree: [%d]", err);
778 _DEBUG_INFO("free mo success");
781 if(mo_parent_node != NULL) {
782 free(mo_parent_node);
783 mo_parent_node = NULL;
790 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)
794 retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
796 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
798 _DEBUG_INFO("sync_agent_dm_mo_type_e : %d", type);
799 _DEBUG_INFO("node_id : %d", mo_node->id);
800 _DEBUG_INFO("will be updated full_path : %s", mo_node->full_path);
805 err_code = dm_mo_update_node_wraper(type, mo_node->full_path, mo_node);
807 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
808 _DEBUG_ERROR("Failed dm_mo_update_node_wraper() : %d", err_code);
813 * Update Framework property tbl
815 if (mo_node->framework_property != NULL) {
816 err_code = dm_mo_update_framework_property_wraper(mo_node->id, mo_node->framework_property);
817 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
818 _DEBUG_ERROR("Failed dm_mo_update_framework_property_wraper() : %d", err_code);
823 * Update Runtime property tbl
825 if (mo_node->runtime_property != NULL) {
826 err_code = dm_mo_update_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
827 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
828 _DEBUG_ERROR("Failed dm_mo_update_runtime_property_wraper() : %d", err_code);
837 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)
841 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
843 _DEBUG_INFO("mo_path : %s", mo_path);
845 sync_agent_dm_mo_error_e err_code = dm_mo_get_child_node_wraper(type, mo_path, mo_node_list, count);
846 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
847 _DEBUG_ERROR("Failed to dm_mo_get_child_node_wraper : [%d]", err_code);
852 if (option == SYNC_AGENT_DM_MO_GET_OPTION_NODE) {
854 return SYNC_AGENT_DM_MO_SUCCESS;
858 * todo Set Property to node list
861 for (; i < *count; i++) {
862 err_code = dm_mo_get_framework_property_wraper((*mo_node_list)[i].id, &((*mo_node_list)[i].framework_property));
863 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
864 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
866 err_code = dm_mo_get_runtime_property_wraper((*mo_node_list)[i].id, &((*mo_node_list)[i].runtime_property));
867 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
868 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
874 return SYNC_AGENT_DM_MO_SUCCESS;
877 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)
881 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
883 sync_agent_dm_mo_error_e err_code = dm_get_mo(mo_path, root_node, option);
884 _DEBUG_INFO("mo_path : %s", mo_path);
885 if(err_code == SYNC_AGENT_DM_MO_FAIL) {
891 err_code = _recursive_get_Descendant_MO_List(type, mo_path, *root_node, count, option);
892 _DEBUG_INFO("get_decendant mo list : %d", err_code);
893 /* __print_Tree(*root_node); */
900 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)
904 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
906 _DEBUG_INFO("mo_path : %s", mo_path);
908 sync_agent_dm_mo_error_e err_code = dm_mo_get_node_wraper(mo_path, mo_node);
909 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
910 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
911 if( err_code == SYNC_AGENT_DM_MO_FAIL) {
912 if( *mo_node != NULL ) {
913 sync_agent_free_mo_item(*mo_node);
919 if (*mo_node == NULL) {
920 return SYNC_AGENT_DM_MO_FAIL;
923 if (option == SYNC_AGENT_DM_MO_GET_OPTION_ALL) {
924 err_code = dm_mo_get_framework_property_wraper((*mo_node)->id, &((*mo_node)->framework_property));
925 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
926 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
929 _DEBUG_INFO("dm_mo_get_framework_property_wraper success");
931 err_code = dm_mo_get_runtime_property_wraper((*mo_node)->id, &((*mo_node)->runtime_property));
932 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
933 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
936 _DEBUG_INFO("dm_mo_get_runtime_property_wraper success");
947 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)
951 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
953 _DEBUG_INFO("mo_path : %s", mo_path);
955 sync_agent_dm_mo_error_e err_code = dm_mo_get_nodes_wraper(mo_path, mo_node);
956 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
957 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
961 if (*mo_node == NULL) {
962 return SYNC_AGENT_DM_MO_FAIL;
965 if (option == SYNC_AGENT_DM_MO_GET_OPTION_ALL) {
967 sync_agent_dm_mo_node_s *iter = NULL;
971 for (iter = *mo_node; iter != NULL; iter = iter->next_node, i++) {
972 _DEBUG_INFO("mo_node id : %d", iter->id);
973 err_code = dm_mo_get_framework_property_wraper(iter->id, &(iter->framework_property));
974 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
975 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
978 _DEBUG_INFO("dm_mo_get_framework_property_wraper success");
980 err_code = dm_mo_get_runtime_property_wraper(iter->id, &(iter->runtime_property));
981 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
982 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
985 _DEBUG_INFO("dm_mo_get_runtime_property_wraper success");
997 EXPORT_API sync_agent_dm_mo_error_e sync_agent_is_exist_mo(const char *mo_path, int *is_exist)
1001 retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
1003 _DEBUG_INFO("mo_path : %s", mo_path);
1005 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1006 err_code = dm_mo_is_exist_node_wraper(mo_path);
1007 _DEBUG_INFO("is exist node : %d", err_code);
1008 if (err_code == SYNC_AGENT_DM_MO_EXIST_NODE) {
1010 } else if (err_code == SYNC_AGENT_DM_MO_NOT_EXIST_NODE) {
1013 _DEBUG_ERROR("dm_mo_is_exist_node_wraper() FAIL !!!");
1016 return SYNC_AGENT_DM_MO_FAIL;
1021 return SYNC_AGENT_DM_MO_SUCCESS;
1024 void dm_free_mo(sync_agent_dm_mo_node_s * mo_node, int count)
1028 _DEBUG_INFO("free mo node start");
1029 if ((mo_node) != NULL && count > 0) {
1031 for (i = 0; i < count; ++i) {
1033 if ((mo_node[i]).name != NULL) {
1034 free((mo_node[i]).name);
1036 if ((mo_node[i]).value != NULL) {
1037 free((mo_node[i]).value);
1039 if ((mo_node[i]).full_path != NULL) {
1040 free((mo_node[i]).full_path);
1042 if ((mo_node[i]).runtime_property != NULL) {
1043 if ((mo_node[i]).runtime_property->acl != NULL) {
1044 free((mo_node[i]).runtime_property->acl);
1046 if ((mo_node[i]).runtime_property->name != NULL) {
1047 free((mo_node[i]).runtime_property->name);
1049 if ((mo_node[i]).runtime_property->size != NULL) {
1050 free((mo_node[i]).runtime_property->size);
1052 if ((mo_node[i]).runtime_property->title != NULL) {
1053 free((mo_node[i]).runtime_property->title);
1055 if ((mo_node[i]).runtime_property->tStamp != NULL) {
1056 free((mo_node[i]).runtime_property->tStamp);
1058 if ((mo_node[i]).runtime_property->type_value != NULL) {
1059 free((mo_node[i]).runtime_property->type_value);
1061 if ((mo_node[i]).runtime_property->verNo != NULL) {
1062 free((mo_node[i]).runtime_property->verNo);
1065 if ((mo_node[i]).framework_property != NULL) {
1066 if ((mo_node[i]).framework_property->defaultValue != NULL) {
1067 free((mo_node[i]).framework_property->defaultValue);
1069 if ((mo_node[i]).framework_property->description != NULL) {
1070 free((mo_node[i]).framework_property->description);
1072 if ((mo_node[i]).framework_property->dfTitle != NULL) {
1073 free((mo_node[i]).framework_property->dfTitle);
1075 if ((mo_node[i]).framework_property->dfType_Value != NULL) {
1076 free((mo_node[i]).framework_property->dfType_Value);
1079 if ((mo_node[i]).child_node_list != NULL) {
1080 dm_free_mo((mo_node[i]).child_node_list, (mo_node[i]).child_node_cnt);
1082 if ((mo_node[i]).next_node != NULL) {
1083 dm_free_mo((mo_node[i]).next_node, 1);
1092 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)
1096 retvm_if(root_ptr == NULL, -1, "root_ptr is NULL !!");
1098 _DEBUG_INFO("[%d] mo_node name : %s", depth, root_ptr->name);
1103 ret = func_ptr(root_ptr, depth, arg);
1104 if (ret != -1 && err_stop != 0) {
1110 for (; i < root_ptr->child_node_cnt; i++) {
1111 ret = sync_agent_traverse_mo_tree_preorder(&(root_ptr->child_node_list[i]), func_ptr, depth + 1, err_stop, arg);
1112 if (ret != -1 && err_stop != 0) {
1122 /******************************************* TNDS ******************************************/
1124 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)
1128 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1130 sync_agent_dm_mo_node_s *root_node = NULL;
1132 sync_agent_dm_mo_error_e err;
1134 err = sync_agent_get_descendant_mo_tree(mo_type, mo_full_path, &root_node, &node_count, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
1135 _DEBUG_INFO("get decendant mo list : %d", err);
1137 sync_agent_dm_mo_error_e mo_error = dm_get_tnds_from_db(tnds_type, root_node, output_stream, byte_size);
1138 _DEBUG_INFO("get tnds mo list : %d", mo_error);
1139 dm_free_mo(root_node, 1);
1146 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)
1150 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1154 return dm_insert_tnds_to_db(tnds_action, tnds_type, mo_type, mo_full_path, input_stream, byte_size);
1157 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_all_mo_table()
1161 sync_agent_dm_mo_error_e err_code = sync_agent_begin_transaction_mo();
1163 err_code = dm_mo_delete_all_node_wraper();
1164 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1165 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1169 err_code = dm_mo_delete_all_framework_property_wraper();
1170 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1171 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1175 err_code = dm_mo_delete_all_runtime_property_wraper();
1176 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1177 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1179 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1187 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)
1191 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1193 *mo_type = dm_mo_get_mo_type_wraper(mo_full_path);
1197 return SYNC_AGENT_DM_MO_SUCCESS;
1200 sync_agent_dm_mo_error_e dm_get_acl_value(const char *mo_full_path, sync_agent_dm_mo_node_s ** mo_node)
1204 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1206 sync_agent_dm_mo_node_s *iter = NULL;
1207 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1209 if (!strcmp(mo_full_path, ".")) {
1210 err_code = dm_mo_get_node_wraper(mo_full_path, mo_node);
1213 err_code = dm_mo_get_nodes_wraper(mo_full_path, mo_node);
1216 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1217 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
1218 return SYNC_AGENT_DM_MO_FAIL;
1220 retvm_if(*mo_node == NULL, SYNC_AGENT_DM_MO_NOT_EXIST_NODE, "mo_node is NULL !!");
1223 for (iter = (*mo_node); iter != NULL; iter = iter->next_node) {
1224 _DEBUG_INFO("iter mo count : %d", i++);
1226 err_code = dm_mo_get_runtime_property_wraper(iter->id, &(iter->runtime_property));
1227 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1228 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
1229 return SYNC_AGENT_DM_MO_FAIL;
1232 err_code = dm_mo_get_framework_property_wraper(iter->id, &(iter->framework_property));
1233 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1234 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
1235 return SYNC_AGENT_DM_MO_FAIL;
1238 if (iter->runtime_property != NULL && iter->runtime_property->acl != NULL) {
1239 _DEBUG_INFO("mo node id : %d", iter->id);
1240 _DEBUG_INFO("mo node acl : %s", iter->runtime_property->acl);
1241 _DEBUG_INFO("current node_acl");
1244 sync_agent_dm_mo_node_s *mo_parent_node = NULL;
1246 err_code = dm_mo_get_node_from_id_wraper(iter->parent_id, &mo_parent_node);
1247 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1248 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err_code);
1249 if(mo_parent_node != NULL) {
1250 free(mo_parent_node);
1252 return SYNC_AGENT_DM_MO_FAIL;
1256 while (mo_parent_node != NULL) {
1258 err_code = dm_mo_get_runtime_property_wraper(mo_parent_node->id, &(mo_parent_node->runtime_property));
1259 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1260 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
1263 if (mo_parent_node->runtime_property != NULL && mo_parent_node->runtime_property->acl != NULL) {
1264 _DEBUG_INFO("current node_acl");
1266 iter->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
1267 if (iter->runtime_property == NULL) {
1268 _DEBUG_ERROR("alloc fail");
1270 dm_free_mo(mo_parent_node, 1);
1271 mo_parent_node = NULL;
1273 return SYNC_AGENT_DM_MO_FAIL;
1276 iter->runtime_property->acl = strdup(mo_parent_node->runtime_property->acl);
1277 dm_free_mo(mo_parent_node, 1);
1278 mo_parent_node = NULL;
1281 _DEBUG_INFO("parent node_acl null");
1284 parent_id = mo_parent_node->parent_id;
1286 dm_free_mo(mo_parent_node, 1);
1287 mo_parent_node = NULL;
1288 if (parent_id == -1) {
1289 _DEBUG_INFO("root node get acl");
1293 err_code = dm_mo_get_node_from_id_wraper(parent_id, &mo_parent_node);
1294 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1295 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err_code);
1297 dm_free_mo(mo_parent_node, 1);
1298 mo_parent_node = NULL;
1300 return SYNC_AGENT_DM_MO_FAIL;
1306 return SYNC_AGENT_DM_MO_SUCCESS;
1310 * check_acl = 0 : not permission acl
1311 * check_acl = 1 : not have accesstype
1312 * check_acl = 2 : permission acl
1314 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)
1318 if (mo_full_path == NULL || server_id == NULL || access_type == SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) {
1319 _DEBUG_INFO("mo_full_path == NULL || acl_value == NULL || access_type == SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET\n");
1321 return SYNC_AGENT_DM_MO_FAIL;
1324 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1325 sync_agent_dm_mo_node_s *mo_node = NULL;
1326 sync_agent_dm_mo_node_s *iter = NULL;
1327 char *mo_acl_value = NULL;
1328 int isSearch_value = 0;
1329 int isExist_all = 0;
1330 int server_id_length = 0;
1331 char *ptr_sev_id = NULL;
1334 err_code = dm_get_acl_value(mo_full_path, &mo_node);
1335 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1340 if (mo_node == NULL) {
1341 _DEBUG_INFO("command_str is NULL");
1343 err_code = SYNC_AGENT_DM_MO_FAIL;
1347 /*check accecctype error */
1348 _DEBUG_INFO("check accesstype : %d", access_type);
1350 if (mo_node->framework_property != NULL) {
1351 _DEBUG_INFO("framework accesstype : %d", mo_node->framework_property->accessType);
1353 if ((mo_node->framework_property->accessType != SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) && (mo_node->framework_property->accessType & access_type) != access_type) {
1360 for (iter = mo_node; iter != NULL; iter = iter->next_node) {
1361 _DEBUG_INFO("check mo node acl iter\n");
1362 if (iter->runtime_property == NULL || iter->runtime_property->acl == NULL) {
1363 _DEBUG_INFO("mo_acl_value is NULL\n");
1365 err_code = SYNC_AGENT_DM_MO_SUCCESS;
1369 mo_acl_value = iter->runtime_property->acl;
1371 _DEBUG_INFO("ALC : %s\n", mo_acl_value);
1373 if (isSearch_value == 2) {
1375 _DEBUG_INFO("acl ok \n");
1377 _DEBUG_INFO("mo_acl_value = %s\n", mo_acl_value);
1378 _DEBUG_INFO("access_type = %d\n", access_type);
1380 char *command_str = NULL;
1381 command_str = _get_access_type_string(access_type);
1382 if (command_str == NULL) {
1383 _DEBUG_INFO("command_str is NULL");
1385 err_code = SYNC_AGENT_DM_MO_FAIL;
1389 /* search acl command and server_id */
1390 char *ptr_cmd = strstr(mo_acl_value, command_str);
1391 while (ptr_cmd != NULL) {
1392 char *mo_server_id = NULL;
1394 _DEBUG_INFO("########## Operation Start ###########");
1395 _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd);
1396 ptr_cmd += strlen(command_str);
1398 _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd);
1399 ptr_sev_id = strstr(ptr_cmd, "&");
1401 if (ptr_sev_id != NULL) {
1402 server_id_length = strlen(ptr_cmd) - strlen(ptr_sev_id - 1) + 1;
1403 _DEBUG_INFO("ptr_sev_id = %s\n", ptr_sev_id);
1405 _DEBUG_INFO("ptr_sev_id = %s\n", ptr_cmd);
1406 server_id_length = strlen(ptr_cmd);
1409 _DEBUG_INFO("server_id_length = %d\n", server_id_length);
1410 mo_server_id = (char *)calloc(server_id_length + 1, sizeof(char));
1411 if (mo_server_id == NULL) {
1412 _DEBUG_ERROR("CALLOC failed !!!");
1414 err_code = SYNC_AGENT_DM_MO_FAIL;
1417 memset(mo_server_id, 0, sizeof(char)*(server_id_length + 1));
1418 strncpy(mo_server_id, ptr_cmd, server_id_length);
1419 _DEBUG_INFO("[ mo_server_id = %s ]\n", mo_server_id);
1421 if (strcmp(mo_server_id, server_id) == 0) {
1422 _DEBUG_INFO("====> Search ACL Server_id");
1425 if (mo_server_id != NULL) {
1427 mo_server_id = NULL;
1431 } else if (strcmp(mo_server_id, "*") == 0) {
1432 _DEBUG_INFO("Exist All Format");
1436 /* prepare next value check */
1437 if (ptr_sev_id != NULL) {
1438 ptr_cmd = strstr(ptr_sev_id, command_str);
1443 if (mo_server_id != NULL) {
1445 mo_server_id = NULL;
1452 if (mo_node != NULL)
1453 dm_free_mo(mo_node, 1);
1455 if (isSearch_value == 0) {
1457 if (isExist_all == 1) {
1458 _DEBUG_INFO("##############################>>>>>> Search Value => exist * format !!");
1465 _DEBUG_INFO("##############################>>>>>> Not Search Value ");
1474 _DEBUG_INFO("##############################>>>>>> Search Value !!");
1484 if (mo_node != NULL) {
1485 dm_free_mo(mo_node, 1);
1492 EXPORT_API sync_agent_dm_mo_error_e sync_agent_create_mo_acc_item(sync_agent_dm_acc_info_s ** acc_info)
1496 *acc_info = (sync_agent_dm_acc_info_s *) calloc(1, sizeof(sync_agent_dm_acc_info_s));
1497 if (*acc_info == NULL) {
1498 return SYNC_AGENT_DM_MO_FAIL;
1503 return SYNC_AGENT_DM_MO_SUCCESS;
1506 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)
1510 sync_agent_dm_mo_error_e mo_error = SYNC_AGENT_DM_MO_SUCCESS;
1512 const char *server_id_string = "ServerID";
1513 const char *acc_type_string = 0;
1515 if (sync_agent_mo_acc_info_item == NULL) {
1516 return SYNC_AGENT_DM_MO_FAIL;
1519 _DEBUG_INFO("get acc info : %d ", sync_agent_mo_acc_info_item->acc_type);
1520 _DEBUG_INFO("get acc info : %s ", sync_agent_mo_acc_info_item->serverid);
1522 switch (sync_agent_mo_acc_info_item->acc_type) {
1523 case DEVICE_MANAGE_ACC_TYPE_SERVER:
1524 acc_type_string = "/ServerAppAuth/";
1526 case DEVICE_MANAGE_ACC_TYPE_CLIENT:
1527 acc_type_string = "/ClientAppAuth/";
1531 /*sync_agent_dm_acc_info_s *acc_info = NULL; */
1532 mo_error = dm_mo_get_acc_info_wraper(sync_agent_mo_acc_info_item->serverid, server_id_string, acc_type_string, acc_info);
1534 if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
1535 _DEBUG_ERROR("Failed to dm_mo_get_acc_info_wraper()");
1539 if (*acc_info != NULL) {
1540 _DEBUG_INFO("auth_name : %s", (*acc_info)->auth_name);
1541 _DEBUG_INFO("auth_secret : %s", (*acc_info)->auth_secret);
1542 _DEBUG_INFO("auth_data : %s", (*acc_info)->auth_data);
1543 _DEBUG_INFO("auth_type : %s", (*acc_info)->auth_type);
1544 _DEBUG_INFO("auth_level : %s", (*acc_info)->auth_level);
1545 _DEBUG_INFO("addr : %s\n", (*acc_info)->addr);
1547 _DEBUG_INFO("\nacc_info is NULL!!\n");
1548 return SYNC_AGENT_DM_MO_FAIL;
1556 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)
1560 sync_agent_dm_mo_error_e mo_error = SYNC_AGENT_DM_MO_SUCCESS;
1561 const char *server_id_string = "ServerID";
1562 const char *acc_type_string = NULL;
1564 if (sync_agent_mo_acc_info_item == NULL) {
1566 return SYNC_AGENT_DM_MO_FAIL;
1569 switch (sync_agent_mo_acc_info_item->acc_type) {
1570 case DEVICE_MANAGE_ACC_TYPE_SERVER:
1571 acc_type_string = "/ServerAppAuth/";
1573 case DEVICE_MANAGE_ACC_TYPE_CLIENT:
1574 acc_type_string = "/ClientAppAuth/";
1578 mo_error = dm_mo_set_acc_info_wraper(sync_agent_mo_acc_info_item->serverid, server_id_string, acc_type_string, acc_info);
1580 if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
1581 _DEBUG_ERROR("Failed to dm_mo_get_acc_info_wraper()");
1585 if (acc_info != NULL) {
1586 _DEBUG_INFO("\nauth_name : %s", acc_info->auth_name);
1587 _DEBUG_INFO("auth_secret : %s", acc_info->auth_secret);
1588 _DEBUG_INFO("auth_data : %s", acc_info->auth_data);
1589 _DEBUG_INFO("auth_type : %s", acc_info->auth_type);
1590 _DEBUG_INFO("auth_level : %s", acc_info->auth_level);
1591 _DEBUG_INFO("addr : %s", acc_info->addr);
1593 _DEBUG_INFO("\nacc_info is NULL!!\n");
1601 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_acc_item(sync_agent_dm_acc_info_s ** acc_info)
1605 if ((*acc_info) != NULL) {
1606 if ((*acc_info)->addr != NULL) {
1607 free((*acc_info)->addr);
1608 (*acc_info)->addr = NULL;
1610 if ((*acc_info)->auth_data != NULL) {
1611 free((*acc_info)->auth_data);
1612 (*acc_info)->auth_data = NULL;
1614 if ((*acc_info)->auth_level != NULL) {
1615 free((*acc_info)->auth_level);
1616 (*acc_info)->auth_level = NULL;
1618 if ((*acc_info)->auth_name != NULL) {
1619 free((*acc_info)->auth_name);
1620 (*acc_info)->auth_name = NULL;
1622 if ((*acc_info)->auth_secret != NULL) {
1623 free((*acc_info)->auth_secret);
1624 (*acc_info)->auth_secret = NULL;
1626 if ((*acc_info)->auth_type != NULL) {
1627 free((*acc_info)->auth_type);
1628 (*acc_info)->auth_type = NULL;
1635 return SYNC_AGENT_DM_MO_SUCCESS;
1638 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)
1642 retvm_if(mo_root == NULL, SYNC_AGENT_DM_MO_FAIL, "uptodate mo root NULL !!");
1644 _DEBUG_INFO("mo_type : %d", mo_type);
1646 sync_agent_dm_mo_node_s *root_node = NULL;
1648 sync_agent_dm_mo_error_e err;
1649 err = sync_agent_get_descendant_mo_tree(mo_type, mo_root, &root_node, &count, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
1650 _DEBUG_INFO("get decendant mo list : %d", err);
1652 plugin_get_mo_value_cb func_point_get_value = NULL;
1653 _DEBUG_INFO("PLUGIN ID : %d", mo_plugin_id);
1654 func_point_get_value = plugin_get_function_get_mo_value(mo_plugin_id);
1656 sync_agent_traverse_mo_tree_preorder(root_node, _update_MO_info, 0, 0, (void **)(&func_point_get_value));
1660 return SYNC_AGENT_DM_MO_SUCCESS;
1663 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_serverinfo(sync_agent_dm_server_info_s ** server_info)
1667 sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
1668 const char *server_id_string = "ServerID";
1670 err = dm_mo_get_server_id_list_wraper(server_id_string, server_info);
1671 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
1672 _DEBUG_INFO("get server id list : %d", err);
1676 _DEBUG_INFO("get server id list result : %d", err);
1681 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_serverinfo(sync_agent_dm_server_info_s * server_info)
1685 if (server_info != NULL) {
1686 if (server_info->server_id != NULL) {
1687 free(server_info->server_id);
1688 server_info->server_id = NULL;
1690 if (server_info->next != NULL) {
1691 sync_agent_free_serverinfo(server_info->next);
1692 server_info->next = NULL;
1700 return SYNC_AGENT_DM_MO_SUCCESS;
1703 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_serverid(sync_agent_dm_mo_type_e mo_type, char **server_id)
1707 _DEBUG_INFO("mo_type : %d", mo_type);
1709 const char *server_id_string = "ServerID";
1711 sync_agent_dm_server_info_s *head_ptr = NULL;
1712 dm_mo_get_server_id_list_wraper(server_id_string, &head_ptr);
1714 sync_agent_dm_server_info_s *cursor_ptr = head_ptr;
1716 while (cursor_ptr != NULL) {
1717 _DEBUG_INFO("server_id : %s", cursor_ptr->server_id);
1718 _DEBUG_INFO("server_type : %d", cursor_ptr->server_type);
1720 int result = mo_type & (cursor_ptr->server_type);
1722 if (result == mo_type) {
1723 _DEBUG_INFO("corrected");
1724 *server_id = g_strdup(cursor_ptr->server_id);
1725 sync_agent_free_serverinfo(head_ptr);
1726 return SYNC_AGENT_DM_MO_SUCCESS;
1729 cursor_ptr = cursor_ptr->next;
1732 sync_agent_free_serverinfo(head_ptr);
1735 return SYNC_AGENT_DM_MO_FAIL;
1738 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_root_path(const char *mo_full_path, char **root_path)
1742 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1743 err_code = dm_mo_get_root_path_wraper(mo_full_path, root_path);
1744 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1745 _DEBUG_ERROR("Failed dm_mo_get_root_path_wraper() : [%d]", err_code);
1746 return SYNC_AGENT_DM_MO_FAIL;
1748 _DEBUG_INFO("Successed dm_mo_get_root_path_wraper() : [%s]", *root_path);
1754 return SYNC_AGENT_DM_MO_SUCCESS;
1757 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_server_type(const char *server_id, int *server_type)
1761 retvm_if((server_id) == NULL, SYNC_AGENT_DM_MO_FAIL, "server_id is NULL!!");
1763 _DEBUG_INFO("server_id : %s", server_id);
1764 const char *server_id_string = "ServerID";
1766 sync_agent_dm_server_info_s *head_ptr = NULL;
1767 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1768 err_code = dm_mo_get_server_id_list_wraper(server_id_string, &head_ptr);
1770 if (err_code != SYNC_AGENT_DM_MO_FAIL) {
1771 sync_agent_dm_server_info_s *cursor_ptr = head_ptr;
1772 while (cursor_ptr != NULL) {
1773 if (cursor_ptr->server_id == NULL) {
1775 sync_agent_free_serverinfo(head_ptr);
1776 return SYNC_AGENT_DM_MO_SUCCESS;
1778 _DEBUG_INFO("server_id : %s", cursor_ptr->server_id);
1779 _DEBUG_INFO("server_type : %d", cursor_ptr->server_type);
1781 if (!strcmp(cursor_ptr->server_id, server_id)) {
1782 _DEBUG_INFO("corrected server_id : %s", server_id);
1783 *server_type = cursor_ptr->server_type;
1784 sync_agent_free_serverinfo(head_ptr);
1785 return SYNC_AGENT_DM_MO_SUCCESS;
1787 cursor_ptr = cursor_ptr->next;
1792 sync_agent_free_serverinfo(head_ptr);
1795 return SYNC_AGENT_DM_MO_FAIL;
1800 sync_agent_free_serverinfo(head_ptr);
1803 return SYNC_AGENT_DM_MO_SUCCESS;
1806 EXPORT_API sync_agent_dm_mo_error_e sync_agent_initialize_mo(int mo_plugin_id)
1810 plugin_initialize func_point_initialize = NULL;
1811 func_point_initialize = plugin_get_function_initialize(mo_plugin_id);
1813 if (func_point_initialize != NULL) {
1814 int result = func_point_initialize();
1816 return SYNC_AGENT_DM_MO_FAIL;
1819 return SYNC_AGENT_DM_MO_FAIL;
1824 return SYNC_AGENT_DM_MO_SUCCESS;
1827 /******************************** static function implement **********************************/
1829 int _update_MO_info(sync_agent_dm_mo_node_s * mo_node, int depth, void **arg)
1833 if (mo_node == NULL) {
1834 _DEBUG_TRACE("mo_node is NULL!!");
1838 _DEBUG_TRACE("mo_node->full_path : %s", mo_node->full_path);
1839 _DEBUG_TRACE("mo_node->name : %s", mo_node->name);
1840 _DEBUG_TRACE("mo_node->value : %s", mo_node->value);
1842 plugin_get_mo_value_cb func_point_get_value = (plugin_get_mo_value_cb) (*arg);
1844 if (func_point_get_value != NULL) {
1845 func_point_get_value(mo_node->full_path, mo_node->name, &(mo_node->value));
1846 _DEBUG_TRACE("Be Called func_point_get_value();");
1848 dm_update_mo(mo_node->mo_type, mo_node);
1856 /******************************************************** Impl static function *************************************************************/
1858 static int _get_parent_path(const char *mo_pull_path, char **mo_parent_path, char **mo_name)
1862 int mo_pull_path_len = strlen(mo_pull_path);
1864 char *last_delimit = strrchr(mo_pull_path, DELIMIT);
1869 if (last_delimit == NULL) {
1870 *mo_name = (char *)calloc(mo_pull_path_len + 1, sizeof(char));
1871 if (*mo_name == NULL) {
1872 _DEBUG_ERROR("CALLOC failed !!!");
1875 strncpy(*mo_name, mo_pull_path, mo_pull_path_len);
1879 int name_len = strlen(last_delimit);
1880 int parent_path_len = mo_pull_path_len - name_len;
1882 *mo_parent_path = (char *)calloc(parent_path_len + 1, sizeof(char));
1883 if (*mo_parent_path == NULL) {
1884 _DEBUG_ERROR("CALLOC failed !!!");
1887 *mo_name = (char *)calloc(name_len, sizeof(char));
1888 if (*mo_name == NULL) {
1889 _DEBUG_ERROR("CALLOC failed !!!");
1893 strncpy(*mo_parent_path, mo_pull_path, parent_path_len);
1894 strncpy(*mo_name, last_delimit + 1, name_len);
1901 static sync_agent_dm_mo_node_s *_create_default_mo_node(char *mo_full_path)
1905 sync_agent_dm_mo_node_s *mo_node = (sync_agent_dm_mo_node_s *) calloc(1, sizeof(sync_agent_dm_mo_node_s));
1906 if (mo_node == NULL) {
1907 _DEBUG_ERROR("CALLOC failed !!!");
1911 char *mo_parent_path = NULL;
1912 char *mo_name = NULL;
1913 int ret = _get_parent_path(mo_full_path, &mo_parent_path, &mo_name);
1915 dm_free_mo(mo_node, 1);
1917 if (mo_parent_path != NULL)
1918 free(mo_parent_path);
1923 _DEBUG_TRACE("mo_full_path : %s", mo_full_path);
1924 _DEBUG_TRACE("mo_parent_path : %s", mo_parent_path);
1925 _DEBUG_TRACE("mo_name : %s", mo_name);
1927 /* if (mo_parent_path != NULL) {
1928 free(mo_parent_path);
1931 mo_node->parent_id = -1;
1932 mo_node->name = mo_name;
1933 mo_node->full_path = mo_full_path;
1934 mo_node->value = NULL;
1936 if (mo_parent_path == NULL) {
1937 mo_node->type = SYNC_AGENT_DM_MO_NODE_ROOT;
1938 _DEBUG_TRACE("------------------root node-----------------");
1940 mo_node->type = SYNC_AGENT_DM_MO_NODE_INTERIOR;
1942 mo_node->framework_property = (sync_agent_dm_mo_framework_property_s *) calloc(1, sizeof(sync_agent_dm_mo_framework_property_s));
1943 if (mo_node->framework_property == NULL) {
1944 _DEBUG_ERROR("CALLOC failed !!!");
1945 dm_free_mo(mo_node, 1);
1946 if (mo_parent_path != NULL)
1947 free(mo_parent_path);
1951 mo_node->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
1952 if (mo_node->runtime_property == NULL) {
1953 _DEBUG_ERROR("CALLOC failed !!!");
1954 dm_free_mo(mo_node, 1);
1955 if (mo_parent_path != NULL)
1956 free(mo_parent_path);
1961 if (mo_node->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
1962 mo_node->framework_property->dffFormat = SYNC_AGENT_DM_MO_FORMAT_NODE;
1963 mo_node->framework_property->accessType = SYNC_AGENT_DM_MO_ACCESSTYPE_ADD | SYNC_AGENT_DM_MO_ACCESSTYPE_GET;
1964 mo_node->runtime_property->acl = strdup("Get=*&Add=*");
1965 mo_node->runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_NODE;
1966 mo_node->runtime_property->name = strdup(".");
1967 _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);
1970 if (mo_parent_path != NULL)
1971 free(mo_parent_path);
1978 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)
1983 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1984 err_code = dm_get_child_mo_list(type, mo_path, &(parent_node->child_node_list), &count, option);
1985 _DEBUG_TRACE("get child mo list err_code_ : %d", err_code);
1986 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1989 parent_node->child_node_cnt = count;
1990 *acc_count = *acc_count + count;
1991 _DEBUG_TRACE("count : %d", count);
1992 _DEBUG_TRACE("acc count : %d", *acc_count);
1993 _DEBUG_TRACE("MO PAHT : %s", mo_path);
1997 for (; i < count; i++) {
1998 _DEBUG_TRACE("RJW : %s", parent_node->child_node_list[i].full_path);
1999 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);
2000 _DEBUG_TRACE("err_code : %d", err_code);
2001 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
2006 return SYNC_AGENT_DM_MO_FAIL;
2014 static char *_get_access_type_string(sync_agent_dm_mo_access_type_e access_type)
2018 char *command_str = NULL;
2020 _DEBUG_TRACE("accessType = %d\n", access_type);
2021 switch (access_type) {
2022 case SYNC_AGENT_DM_MO_ACCESSTYPE_ADD:
2023 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_ADD");
2024 command_str = "Add=";
2026 case SYNC_AGENT_DM_MO_ACCESSTYPE_COPY:
2027 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_COPY");
2028 command_str = "Copy=";
2030 case SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE:
2031 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE");
2032 command_str = "Delete=";
2034 case SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC:
2035 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC");
2036 command_str = "Exec=";
2038 case SYNC_AGENT_DM_MO_ACCESSTYPE_GET:
2039 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_GET");
2040 command_str = "Get=";
2042 case SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE:
2043 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE");
2044 command_str = "Replace=";
2047 _DEBUG_TRACE("can not execute logic");
2050 _DEBUG_TRACE("command string = %s\n", command_str);
2057 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)
2061 if (mo_node == NULL || server_id_list == NULL) {
2062 _DEBUG_ERROR("mo_node == 0 || server_id_list == 0\n");
2063 return SYNC_AGENT_DM_MO_FAIL;
2066 sync_agent_dm_mo_framework_property_s *framework_property = mo_node->framework_property;
2067 sync_agent_dm_mo_runtime_property_s *runtime_property = mo_node->runtime_property;
2069 /* set format, type, type value, title property for framework property */
2070 runtime_property->format = framework_property->dffFormat;
2071 runtime_property->type = framework_property->dfType;
2073 _DEBUG_VERBOSE("FP[dffFormat = %d], RT[format = %d]", framework_property->dffFormat, runtime_property->format);
2074 _DEBUG_VERBOSE("FP[dfType = %d], RT[type = %d]", framework_property->dfType, runtime_property->type);
2076 if (framework_property->dfType_Value != NULL) {
2077 runtime_property->type_value = strdup(framework_property->dfType_Value);
2078 _DEBUG_VERBOSE("FP[dfType_Value = %s], RT[type_value = %s]", framework_property->dfType_Value, runtime_property->type_value);
2081 if (framework_property->dfTitle != NULL) {
2082 runtime_property->title = strdup(framework_property->dfTitle);
2083 _DEBUG_VERBOSE("FP[dfTitle = %s], RT[title = %s]", framework_property->dfTitle, runtime_property->title);
2086 /* set name for mo_node */
2087 if (mo_node->name != NULL) {
2088 runtime_property->name = strdup(mo_node->name);
2089 _DEBUG_VERBOSE("mo_name[name = %s], RT[name = %s]", mo_node->name, runtime_property->name);
2092 /* set version No, size */
2093 runtime_property->verNo = strdup("0");
2094 runtime_property->size = 0;
2097 SYNC_AGENT_UTIL_TIME_T current_time;
2098 SYNC_AGENT_UTIL_TIME(¤t_time);
2100 SYNC_AGENT_UTIL_TM *time;
2101 time = SYNC_AGENT_UTIL_LOCALTIME(¤t_time);
2103 _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);
2105 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);
2106 _DEBUG_VERBOSE("RT[tStamp = %s]", runtime_property->tStamp);
2109 if (runtime_property->acl != NULL) {
2110 /*aready this is setted runtime property acl */
2112 return SYNC_AGENT_DM_MO_SUCCESS;
2115 int total_acl_size = 0;
2116 if (server_id_list_cnt > 0) {
2119 for (i = 0; i < server_id_list_cnt; i++) {
2120 if (server_id_list[i] == NULL) {
2121 _DEBUG_ERROR("server_id_list[%d] == NULL", i);
2122 return SYNC_AGENT_DM_MO_FAIL;
2124 _DEBUG_VERBOSE("server_id_list[%d] = %s, length = %d", i, server_id_list[i], strlen(server_id_list[i]));
2125 total_acl_size += ((10 * DEVICE_MANAGER_MO_ACCESSTYPE_CNT) + strlen(server_id_list[i]));
2128 char *total_acl_value = (char *)calloc(total_acl_size, sizeof(char));
2129 if (total_acl_value == NULL) {
2130 _DEBUG_ERROR("CALLOC failed !!!");
2131 return SYNC_AGENT_DM_MO_FAIL;
2133 int total_acl_value_idx = 0;
2135 sync_agent_dm_mo_access_type_e access_type = SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET;
2136 char *command_str = NULL;
2138 int temp_acl_value_size = 0;
2139 char *temp_acl_value = NULL;
2142 for (i = 1; i <= DEVICE_MANAGER_MO_ACCESSTYPE_CNT; i++) {
2144 _DEBUG_VERBOSE("framework_property->accessType = %d\n", framework_property->accessType);
2145 if (framework_property->accessType != SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) {
2147 access_type = framework_property->accessType & (mul);
2148 _DEBUG_VERBOSE("accessType = %d\n", access_type);
2149 command_str = _get_access_type_string(access_type);
2151 if (command_str != NULL) {
2152 for (j = 0; j < server_id_list_cnt; j++) {
2154 _DEBUG_VERBOSE("server_id_list[%d] = %s", j, server_id_list[j]);
2155 if (i == DEVICE_MANAGER_MO_ACCESSTYPE_CNT && j == server_id_list_cnt - 1) {
2156 temp_acl_value = g_strdup_printf("%s%s", command_str, server_id_list[j]);
2158 temp_acl_value = g_strdup_printf("%s%s&", command_str, server_id_list[j]);
2161 temp_acl_value_size = strlen(temp_acl_value);
2163 _DEBUG_VERBOSE("temp_acl_value = %s\n", temp_acl_value);
2164 memcpy(total_acl_value + total_acl_value_idx, temp_acl_value, temp_acl_value_size);
2165 total_acl_value_idx += temp_acl_value_size;
2175 _DEBUG_VERBOSE("total_acl_value = %s\n", total_acl_value);
2176 runtime_property->acl = total_acl_value;
2181 return SYNC_AGENT_DM_MO_SUCCESS;
2184 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)
2188 sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
2190 if (mo_node == NULL) {
2191 return SYNC_AGENT_DM_MO_FAIL;
2194 _DEBUG_TRACE("[%s] [%s] [%d] [%d]", mo_node->name, mo_node->full_path, mo_node->type, mo_node->child_node_cnt);
2195 _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,
2196 mo_node->framework_property->scope, mo_node->framework_property->dfTitle, mo_node->framework_property->dfType);
2197 _DEBUG_TRACE("================================================================================");
2200 * Setting acl of RuntimeProperty in PlugIn
2204 * Set MO Value from PlugIn
2206 if (func_point_get_value != NULL) {
2207 func_point_get_value(mo_node->full_path, mo_node->name, &(mo_node->value));
2208 _DEBUG_TRACE("mo value [%s] ", mo_node->value);
2211 mo_node->server_type = server_type;
2212 err = dm_mo_add_node_wraper(mo_type, mo_node);
2213 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2214 _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
2217 err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
2218 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2219 _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
2223 _DEBUG_TRACE("set_mo_run Start");
2224 err = __set_MO_RunTimeProperty(server_id_list, server_id_list_cnt, mo_node);
2225 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2226 _DEBUG_ERROR("Failed __set_MO_RunTimeProperty() : [%d]", err);
2230 _DEBUG_TRACE("set_mo_run ENd");
2231 err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
2232 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2233 _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
2237 sync_agent_dm_mo_node_s *pCursor = mo_node->child_node_list;
2238 while (pCursor != NULL) {
2239 pCursor->parent_id = mo_node->id;
2241 err = _add_MO_Tree(mo_type, pCursor, func_point_get_value, server_id_list, server_id_list_cnt, server_type);
2242 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2246 pCursor = pCursor->next_node;
2255 static void __print_Tree(sync_agent_dm_mo_node_s * root_ptr, int depth)
2257 if (root_ptr == NULL) {
2261 // for ( ; i < depth; i++) {
2262 // _DEBUG_INFO("\t");
2264 _DEBUG_INFO("[%s] [%s] [%d] [%d]", root_ptr->name, root_ptr->full_path, root_ptr->type, root_ptr->child_node_cnt);
2265 _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);
2266 _DEBUG_INFO("================================================================================");
2268 sync_agent_dm_mo_node_s *pCursor = root_ptr->child_node_list;
2269 while (pCursor != NULL) {
2270 __print_Tree(pCursor, depth + 1);
2271 pCursor = pCursor->next_node;