[Internal: merge private->RSA , Patch create momanager.db]
[platform/core/system/sync-agent.git] / src / framework / device-manager / mo_accessor.c
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "utility/sync_util.h"
19
20 #include "plugin/mo_plugin.h"
21
22 #include "data-adapter/common.h"
23
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"
29
30 #include "utility/fw_time.h"
31
32 #include <stdlib.h>
33 #include <string.h>
34
35 #ifndef EXPORT_API
36 #define EXPORT_API __attribute__ ((visibility("default")))
37 #endif
38
39 #ifndef SYNC_AGENT_LOG
40 #undef LOG_TAG
41 #define LOG_TAG "AF_MO"
42 #endif
43
44 #define DELIMIT '/'
45
46 static int _get_parent_path(const char *mo_pull_path, char **mo_parent_path, char **mo_name);
47
48 static sync_agent_dm_mo_node_s *_create_default_mo_node(char *mo_full_path);
49
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);
51
52 static char *_get_access_type_string(sync_agent_dm_mo_access_type_e access_type);
53
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);
55
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);
57
58 /* static void __print_Tree(sync_agent_dm_mo_node_s * root_ptr, int depth); // to Debugging */
59
60 static int _update_MO_info(sync_agent_dm_mo_node_s * mo_node, int depth, void **arg);
61
62 EXPORT_API sync_agent_dm_mo_error_e sync_agent_open_mo()
63 {
64         _EXTERN_FUNC_ENTER;
65
66         _EXTERN_FUNC_EXIT;
67
68         return dm_mo_open("/opt/usr/dbspace/.momanager.db");
69 }
70
71 EXPORT_API sync_agent_dm_mo_error_e sync_agent_close_mo()
72 {
73         _EXTERN_FUNC_ENTER;
74
75         _EXTERN_FUNC_EXIT;
76
77         return dm_mo_close();
78 }
79
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)
81 {
82         _EXTERN_FUNC_ENTER;
83
84         retvm_if(vendar_file == NULL, SYNC_AGENT_DM_MO_FAIL, "vendar_file is NULL !!");
85
86         _DEBUG_INFO("vender_file = %s", vendar_file);
87         char *root_node_path = strdup(".");
88
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;
93         }
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) {
96                 return err_code;
97         }
98
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);
101
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);
104
105         retvm_if(func_point_get_server_id_list == NULL, SYNC_AGENT_DM_MO_FAIL, "cannot get plugin_get_server_id_list_cb !!");
106
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);
111
112         err_code = sync_agent_begin_transaction_mo();
113
114         err_code = _add_MO_Tree(mo_type, root_node, func_point_get_value, server_id_list, server_id_list_cnt, server_type);
115
116         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
117                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
118         } else {
119                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
120         }
121
122         _EXTERN_FUNC_EXIT;
123
124         return err_code;
125 }
126
127 EXPORT_API sync_agent_dm_mo_error_e sync_agent_begin_transaction_mo()
128 {
129         _EXTERN_FUNC_ENTER;
130
131         _EXTERN_FUNC_EXIT;
132
133         return dm_mo_begin_transaction_wraper();
134 }
135
136 EXPORT_API sync_agent_dm_mo_error_e sync_agent_end_transaction_mo(sync_agent_dm_mo_transaction_e transaction)
137 {
138         _EXTERN_FUNC_ENTER;
139
140         sync_agent_da_transaction_e transation_option;
141
142         if (transaction == SYNC_AGENT_DM_MO_TRANSACTION_COMMIT) {
143                 transation_option = SYNC_AGENT_DA_TRANSACTION_COMMIT;
144         } else {
145                 transation_option = SYNC_AGENT_DA_TRANSACTION_ROLLBACK;
146         }
147
148         _EXTERN_FUNC_EXIT;
149
150         return dm_mo_end_transaction_wraper(transation_option);
151 }
152
153 sync_agent_dm_mo_error_e dm_create_mo(sync_agent_dm_mo_node_s ** sync_agent_dm_mo_node)
154 {
155         _EXTERN_FUNC_ENTER;
156
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;
160         }
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;
164         }
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;
168         }
169
170         _EXTERN_FUNC_EXIT;
171
172         return SYNC_AGENT_DM_MO_SUCCESS;
173 }
174
175 EXPORT_API sync_agent_dm_mo_error_e sync_agent_create_mo_item(sync_agent_dm_mo_node_s ** sync_agent_mo_item)
176 {
177         _EXTERN_FUNC_ENTER;
178
179         _EXTERN_FUNC_EXIT;
180
181         return dm_create_mo(sync_agent_mo_item);
182 }
183
184 EXPORT_API sync_agent_dm_mo_error_e sync_agent_add_mo_item(sync_agent_dm_mo_node_s * sync_agent_mo_item)
185 {
186         _EXTERN_FUNC_ENTER;
187
188         retvm_if(sync_agent_mo_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
189
190         _EXTERN_FUNC_EXIT;
191
192         return dm_add_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path, sync_agent_mo_item);
193 }
194
195 EXPORT_API sync_agent_dm_mo_error_e sync_agent_update_mo_item(sync_agent_dm_mo_node_s * sync_agent_item)
196 {
197         _EXTERN_FUNC_ENTER;
198
199         retvm_if(sync_agent_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
200
201         _EXTERN_FUNC_EXIT;
202
203         return dm_update_mo(sync_agent_item->mo_type, sync_agent_item);
204 }
205
206 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_mo_item(const char *mo_path)
207 {
208         _EXTERN_FUNC_ENTER;
209
210         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
211
212         sync_agent_dm_mo_type_e mo_type = dm_mo_get_mo_type_wraper(mo_path);
213
214         _EXTERN_FUNC_EXIT;
215
216         return dm_delete_mo(mo_type, mo_path);
217 }
218
219 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_mo_tree_item(const char *mo_path)
220 {
221         _EXTERN_FUNC_ENTER;
222
223         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
224
225         _EXTERN_FUNC_EXIT;
226
227         return dm_delete_mo_tree(mo_path);
228 }
229
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)
231 {
232         _EXTERN_FUNC_ENTER;
233
234         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
235
236         _EXTERN_FUNC_EXIT;
237
238         return dm_get_mo(mo_path, sync_agent_mo_item, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
239 }
240
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)
242 {
243         _EXTERN_FUNC_ENTER;
244
245         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
246
247         _EXTERN_FUNC_EXIT;
248
249         return dm_get_mos(mo_path, sync_agent_mo_item, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
250 }
251
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)
253 {
254         _EXTERN_FUNC_ENTER;
255
256         retvm_if(sync_agent_mo_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_item_s is NULL !!");
257
258         sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
259         int count = 0;
260         sync_agent_dm_mo_node_s *mo_node_list = NULL;
261
262         if (sync_agent_mo_item->interface_type == MO_ITEM_CHILD_MO_VALUE_LIST) {
263
264                 retvm_if(sync_agent_mo_item->mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
265
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;
270                 }
271                 _DEBUG_INFO("get child mo list count : %d", count);
272
273                 int i;
274                 for (i = 0; i < count; ++i) {
275                         *list = g_list_append(*list, &(mo_node_list[i]));
276                 }
277
278                 return SYNC_AGENT_DM_MO_SUCCESS;
279
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;
284                 }
285
286                 *list = g_list_append(*list, mo_node_list);
287
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;
293                 }
294
295                 *list = g_list_append(*list, mo_node_list);
296
297                 return SYNC_AGENT_DM_MO_SUCCESS;
298         }
299
300         _EXTERN_FUNC_EXIT;
301
302         return SYNC_AGENT_DM_MO_FAIL;
303 }
304
305 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_item(sync_agent_dm_mo_node_s * sync_agent_mo_item)
306 {
307         _EXTERN_FUNC_ENTER;
308
309         if (sync_agent_mo_item != NULL) {
310                 dm_free_mo(sync_agent_mo_item, 1);
311         }
312
313         _EXTERN_FUNC_EXIT;
314
315         return SYNC_AGENT_DM_MO_SUCCESS;
316 }
317
318 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_item_list(GList * list)
319 {
320         _EXTERN_FUNC_ENTER;
321
322         retvm_if(list == NULL, SYNC_AGENT_DM_MO_FAIL, "list is NULL !!");
323
324         int count = 0;
325         count = g_list_length(list);
326         _DEBUG_INFO(" mo list length : %d", count);
327         dm_free_mo(list->data, count);
328
329         g_list_free(list);
330
331         _EXTERN_FUNC_EXIT;
332
333         return SYNC_AGENT_DM_MO_FAIL;
334 }
335
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)
337 {
338         _EXTERN_FUNC_ENTER;
339
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 !!");
342
343         sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
344
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("===============================================");
351
352         /*
353          * Get Parent Node from MO DB using by mo_parent_path
354          */
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;
362         }
363
364         if (isRootNode) {
365                 _DEBUG_INFO("is root node");
366                 /*
367                  * Add MO Node to MO DB
368                  */
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);
372                         if (mo_name != NULL)
373                                 free(mo_name);
374                         return err;
375                 }
376
377                 /*
378                  * Add MO Properties to MO DB
379                  */
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);
385                         }
386                 }
387
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);
393                         }
394                 }
395
396                 if (mo_name != NULL)
397                         free(mo_name);
398
399                 return SYNC_AGENT_DM_MO_SUCCESS;
400         }
401
402         _DEBUG_INFO("mo_parent_path : %s", mo_parent_path);
403         _DEBUG_INFO("mo_name : %s", mo_name);
404
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);
409
410         real_mo_parent_node = mo_parent_node;
411         if (real_mo_parent_node == NULL) {
412                 /*
413                  * Create Parent MO Node (Default MO Node)
414                  */
415                 _DEBUG_INFO("parent node empty");
416                 real_mo_parent_node = _create_default_mo_node(mo_parent_path);
417
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) {
420                         if (mo_name != NULL)
421                                 free(mo_name);
422                         return err;
423                 }
424         } else {
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);
430
431                         if (real_mo_parent_node->server_type == mo_node->server_type) {
432                                 _DEBUG_INFO("mo server type : %d", mo_node->server_type);
433                                 break;
434                         }
435                         _DEBUG_INFO("this node is not parent node");
436                         real_mo_parent_node = real_mo_parent_node->next_node;
437                 }
438
439                 if (real_mo_parent_node == NULL) {
440                         real_mo_parent_node = mo_parent_node;
441                 }
442         }
443
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;
447
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);
452
453         /*
454          * Add MO Node to MO DB
455          */
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);
460                 return err;
461         }
462
463         /*
464          * Add MO Properties to MO DB
465          */
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);
471                 }
472         }
473
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);
479                 }
480         }
481
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("================================================");
485
486         dm_free_mo(mo_parent_node, 1);
487
488         _EXTERN_FUNC_EXIT;
489
490         return SYNC_AGENT_DM_MO_SUCCESS;
491 }
492
493 sync_agent_dm_mo_error_e dm_delete_mo(sync_agent_dm_mo_type_e type, const char *mo_full_path)
494 {
495         _EXTERN_FUNC_ENTER;
496
497         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
498
499         _DEBUG_INFO("mo_full_path  : %s", mo_full_path);
500
501         sync_agent_dm_mo_node_s *target_node = NULL;
502         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
503
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;
509         }
510
511         /*
512          * Delete All Child Nodes(Recursive)
513          */
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) {
515                 /*
516                  * Get all right Child Node list
517                  */
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);
523
524                 if (child_node_list != NULL) {
525                         int i = 0;
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);
532
533                                         dm_free_mo(child_node_list, child_node_count);
534
535                                         return SYNC_AGENT_DM_MO_FAIL;
536                                 }
537                         }
538                 }
539
540                 dm_free_mo(child_node_list, child_node_count);
541         } else {
542                 _DEBUG_INFO("leaf node");
543         }
544
545         /*
546          * Delete sync_agent_dm_mo_node_s, MO Properties In MO DB using by mo_node_id
547          */
548         _DEBUG_INFO("target_node->id : %d", target_node->id);
549
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);
553         }
554
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);
558         }
559
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);
563         }
564
565         dm_free_mo(target_node, 1);
566
567         _EXTERN_FUNC_EXIT;
568
569         return SYNC_AGENT_DM_MO_SUCCESS;
570 }
571
572 sync_agent_dm_mo_error_e dm_delete_mo_tree(const char *mo_path)
573 {
574         _EXTERN_FUNC_ENTER;
575
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;
579         int is_exist = 0;
580
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");
584                 _EXTERN_FUNC_EXIT;
585                 return SYNC_AGENT_DM_MO_FAIL;
586         }
587
588         if (is_exist != 1) {
589                 _DEBUG_ERROR("remove dm_acc fail because dm acc %s not existed", mo_path);
590                 _EXTERN_FUNC_EXIT;
591                 return SYNC_AGENT_DM_MO_NOT_EXIST_NODE;
592         }
593
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");
597
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);
602                         } else {
603                                 _DEBUG_INFO("free mo success");
604                         }
605                 }
606
607                 _EXTERN_FUNC_EXIT;
608                 return SYNC_AGENT_DM_MO_FAIL;
609         }
610
611         if (sync_agent_mo_item->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
612
613                 /*first node */
614                 sync_agent_dm_mo_node_s *iter = NULL;
615                 int i = 0;
616
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);
620                 }
621
622                 for (iter = sync_agent_mo_item; iter != NULL; iter = iter->next_node, i++) {
623                         _DEBUG_INFO("mo_node id : %d", iter->id);
624
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);
629                                 goto error;
630                         }
631
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);
635                                 goto error;
636                         }
637
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);
641                                 goto error;
642                         }
643                 }
644
645         } else if (sync_agent_mo_item->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
646
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);
650                         goto error;
651                 }
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);
655                         goto error;
656                 }
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);
660                         goto error;
661                 }
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);
665                         goto error;
666                 }
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);
670                         goto error;
671                 }
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);
675                         goto error;
676                 }
677
678         } else {
679                 /*not root node, first node */
680
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);
684                         goto error;
685                 }
686
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);
691                         goto error;
692                 }
693
694                 while (1) {
695
696                         int parent_id = 0;
697                         parent_id = mo_parent_node->parent_id;
698
699                         if (mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_ROOT || mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
700
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);
704                                         goto error;
705                                 }
706
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);
710                                         goto error;
711                                 }
712
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);
716                                         goto error;
717                                 }
718
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);
723                                                 goto error;
724                                         } else {
725                                                 _DEBUG_INFO("free mo success");
726                                         }
727
728                                         break;
729                                 }
730
731                         } else {
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);
736                                         goto error;
737                                 }
738                         }
739
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);
743                                 goto error;
744                         } else {
745                                 _DEBUG_INFO("free mo success");
746                         }
747
748                         mo_parent_node = NULL;
749
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);
754                                 goto error;
755                         }
756                 }
757         }
758
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);
762                 goto error;
763         } else {
764                 _DEBUG_INFO("free mo success");
765         }
766
767         _EXTERN_FUNC_EXIT;
768         return err;
769
770  error:
771
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);
775         } else {
776                 _DEBUG_INFO("free mo success");
777         }
778
779         if(mo_parent_node != NULL) {
780                 free(mo_parent_node);
781                 mo_parent_node = NULL;
782         }
783
784         _EXTERN_FUNC_EXIT;
785         return err;
786 }
787
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)
789 {
790         _EXTERN_FUNC_ENTER;
791
792         retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
793
794         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
795
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);
799
800         /*
801          * Update MO Node tbl
802          */
803         err_code = dm_mo_update_node_wraper(type, mo_node->full_path, mo_node);
804
805         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
806                 _DEBUG_ERROR("Failed dm_mo_update_node_wraper() : %d", err_code);
807                 return err_code;
808         }
809
810         /*
811          * Update Framework property tbl
812          */
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);
817                 }
818         }
819
820         /*
821          * Update Runtime property tbl
822          */
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);
827                 }
828         }
829
830         _EXTERN_FUNC_EXIT;
831
832         return err_code;
833 }
834
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)
836 {
837         _EXTERN_FUNC_ENTER;
838
839         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
840
841         _DEBUG_INFO("mo_path : %s", mo_path);
842
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);
846                 _EXTERN_FUNC_EXIT;
847                 return err_code;
848         }
849
850         if (option == SYNC_AGENT_DM_MO_GET_OPTION_NODE) {
851                 _EXTERN_FUNC_EXIT;
852                 return SYNC_AGENT_DM_MO_SUCCESS;
853         }
854
855         /*
856          * todo Set Property to node list
857          */
858         int i = 0;
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);
863                 }
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);
867                 }
868         }
869
870         _EXTERN_FUNC_EXIT;
871
872         return SYNC_AGENT_DM_MO_SUCCESS;
873 }
874
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)
876 {
877         _EXTERN_FUNC_ENTER;
878
879         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
880
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) {
884                 return err_code;
885         }
886         /*
887          * Recursive Call
888          */
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); */
892
893         _EXTERN_FUNC_EXIT;
894
895         return err_code;
896 }
897
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)
899 {
900         _EXTERN_FUNC_ENTER;
901
902         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
903
904         _DEBUG_INFO("mo_path : %s", mo_path);
905
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);
912                         }
913                 }
914                 return err_code;
915         }
916
917         if (*mo_node == NULL) {
918                 return SYNC_AGENT_DM_MO_FAIL;
919         }
920
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);
925                         goto error;
926                 } else {
927                         _DEBUG_INFO("dm_mo_get_framework_property_wraper success");
928                 }
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);
932                         goto error;
933                 } else {
934                         _DEBUG_INFO("dm_mo_get_runtime_property_wraper success");
935                 }
936         }
937
938         _EXTERN_FUNC_EXIT;
939
940         return err_code;
941  error:
942         return err_code;
943 }
944
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)
946 {
947         _EXTERN_FUNC_ENTER;
948
949         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
950
951         _DEBUG_INFO("mo_path : %s", mo_path);
952
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);
956                 return err_code;
957         }
958
959         if (*mo_node == NULL) {
960                 return SYNC_AGENT_DM_MO_FAIL;
961         }
962
963         if (option == SYNC_AGENT_DM_MO_GET_OPTION_ALL) {
964
965                 sync_agent_dm_mo_node_s *iter = NULL;
966                 int i = 0;
967                 iter = *mo_node;
968
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);
974                                 goto error;
975                         } else {
976                                 _DEBUG_INFO("dm_mo_get_framework_property_wraper success");
977                         }
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);
981                                 goto error;
982                         } else {
983                                 _DEBUG_INFO("dm_mo_get_runtime_property_wraper success");
984                         }
985                 }
986         }
987
988         _EXTERN_FUNC_EXIT;
989
990         return err_code;
991  error:
992         return err_code;
993 }
994
995 EXPORT_API sync_agent_dm_mo_error_e sync_agent_is_exist_mo(const char *mo_path, int *is_exist)
996 {
997         _EXTERN_FUNC_ENTER;
998
999         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
1000
1001         _DEBUG_INFO("mo_path : %s", mo_path);
1002
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) {
1007                 *is_exist = 1;
1008         } else if (err_code == SYNC_AGENT_DM_MO_NOT_EXIST_NODE) {
1009                 *is_exist = 0;
1010         } else {
1011                 _DEBUG_ERROR("dm_mo_is_exist_node_wraper() FAIL !!!");
1012                 *is_exist = 0;
1013                 _EXTERN_FUNC_EXIT;
1014                 return SYNC_AGENT_DM_MO_FAIL;
1015         }
1016
1017         _EXTERN_FUNC_EXIT;
1018
1019         return SYNC_AGENT_DM_MO_SUCCESS;
1020 }
1021
1022 void dm_free_mo(sync_agent_dm_mo_node_s * mo_node, int count)
1023 {
1024         _EXTERN_FUNC_ENTER;
1025
1026         _DEBUG_INFO("free mo node start");
1027         if ((mo_node) != NULL && count > 0) {
1028                 int i = 0;
1029                 for (i = 0; i < count; ++i) {
1030
1031                         if ((mo_node[i]).name != NULL) {
1032                                 free((mo_node[i]).name);
1033                         }
1034                         if ((mo_node[i]).value != NULL) {
1035                                 free((mo_node[i]).value);
1036                         }
1037                         if ((mo_node[i]).full_path != NULL) {
1038                                 free((mo_node[i]).full_path);
1039                         }
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);
1043                                 }
1044                                 if ((mo_node[i]).runtime_property->name != NULL) {
1045                                         free((mo_node[i]).runtime_property->name);
1046                                 }
1047                                 if ((mo_node[i]).runtime_property->size != NULL) {
1048                                         free((mo_node[i]).runtime_property->size);
1049                                 }
1050                                 if ((mo_node[i]).runtime_property->title != NULL) {
1051                                         free((mo_node[i]).runtime_property->title);
1052                                 }
1053                                 if ((mo_node[i]).runtime_property->tStamp != NULL) {
1054                                         free((mo_node[i]).runtime_property->tStamp);
1055                                 }
1056                                 if ((mo_node[i]).runtime_property->type_value != NULL) {
1057                                         free((mo_node[i]).runtime_property->type_value);
1058                                 }
1059                                 if ((mo_node[i]).runtime_property->verNo != NULL) {
1060                                         free((mo_node[i]).runtime_property->verNo);
1061                                 }
1062                         }
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);
1066                                 }
1067                                 if ((mo_node[i]).framework_property->description != NULL) {
1068                                         free((mo_node[i]).framework_property->description);
1069                                 }
1070                                 if ((mo_node[i]).framework_property->dfTitle != NULL) {
1071                                         free((mo_node[i]).framework_property->dfTitle);
1072                                 }
1073                                 if ((mo_node[i]).framework_property->dfType_Value != NULL) {
1074                                         free((mo_node[i]).framework_property->dfType_Value);
1075                                 }
1076                         }
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);
1079                         }
1080                         if ((mo_node[i]).next_node != NULL) {
1081                                 dm_free_mo((mo_node[i]).next_node, 1);
1082                         }
1083                 }
1084
1085                 free(mo_node);
1086         }
1087         _EXTERN_FUNC_EXIT;
1088 }
1089
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)
1091 {
1092         _EXTERN_FUNC_ENTER;
1093
1094         retvm_if(root_ptr == NULL, -1, "root_ptr is NULL !!");
1095
1096         _DEBUG_INFO("[%d] mo_node name : %s", depth, root_ptr->name);
1097
1098         int ret = 0;
1099
1100         if (depth != 0) {
1101                 ret = func_ptr(root_ptr, depth, arg);
1102                 if (ret != -1 && err_stop != 0) {
1103                         return ret;
1104                 }
1105         }
1106
1107         int i = 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) {
1111                         return ret;
1112                 }
1113         }
1114
1115         _EXTERN_FUNC_EXIT;
1116
1117         return ret;
1118 }
1119
1120 /******************************************* TNDS ******************************************/
1121
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)
1123 {
1124         _EXTERN_FUNC_ENTER;
1125
1126         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1127
1128         sync_agent_dm_mo_node_s *root_node = NULL;
1129         int node_count = 0;
1130         sync_agent_dm_mo_error_e err;
1131
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);
1134
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);
1138
1139         _EXTERN_FUNC_EXIT;
1140
1141         return mo_error;
1142 }
1143
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)
1145 {
1146         _EXTERN_FUNC_ENTER;
1147
1148         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1149
1150         _EXTERN_FUNC_EXIT;
1151
1152         return dm_insert_tnds_to_db(tnds_action, tnds_type, mo_type, mo_full_path, input_stream, byte_size);
1153 }
1154
1155 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_all_mo_table()
1156 {
1157         _EXTERN_FUNC_ENTER;
1158
1159         sync_agent_dm_mo_error_e err_code = sync_agent_begin_transaction_mo();
1160
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);
1164                 return err_code;
1165         }
1166
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);
1170                 return err_code;
1171         }
1172
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);
1176         } else {
1177                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1178         }
1179
1180         _EXTERN_FUNC_EXIT;
1181
1182         return err_code;
1183 }
1184
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)
1186 {
1187         _EXTERN_FUNC_ENTER;
1188
1189         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1190
1191         *mo_type = dm_mo_get_mo_type_wraper(mo_full_path);
1192
1193         _EXTERN_FUNC_EXIT;
1194
1195         return SYNC_AGENT_DM_MO_SUCCESS;
1196 }
1197
1198 sync_agent_dm_mo_error_e dm_get_acl_value(const char *mo_full_path, sync_agent_dm_mo_node_s ** mo_node)
1199 {
1200         _EXTERN_FUNC_ENTER;
1201
1202         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1203
1204         sync_agent_dm_mo_node_s *iter = NULL;
1205         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1206
1207         if (!strcmp(mo_full_path, ".")) {
1208                 err_code = dm_mo_get_node_wraper(mo_full_path, mo_node);
1209         } else {
1210                 /* get nodes */
1211                 err_code = dm_mo_get_nodes_wraper(mo_full_path, mo_node);
1212
1213         }
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;
1217         }
1218         retvm_if(*mo_node == NULL, SYNC_AGENT_DM_MO_NOT_EXIST_NODE, "mo_node is NULL !!");
1219
1220         int i = 0;
1221         for (iter = (*mo_node); iter != NULL; iter = iter->next_node) {
1222                 _DEBUG_INFO("iter mo count : %d", i++);
1223
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;
1228                 }
1229
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;
1234                 }
1235
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");
1240                         continue;
1241                 } else {
1242                         sync_agent_dm_mo_node_s *mo_parent_node = NULL;
1243
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);
1249                                 }
1250                                 return SYNC_AGENT_DM_MO_FAIL;
1251                         }
1252                         int parent_id = -1;
1253
1254                         while (mo_parent_node != NULL) {
1255
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);
1259                                 }
1260
1261                                 if (mo_parent_node->runtime_property != NULL && mo_parent_node->runtime_property->acl != NULL) {
1262                                         _DEBUG_INFO("current node_acl");
1263
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");
1267
1268                                                 dm_free_mo(mo_parent_node, 1);
1269                                                 mo_parent_node = NULL;
1270
1271                                                 return SYNC_AGENT_DM_MO_FAIL;
1272                                         }
1273
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;
1277                                         break;
1278                                 } else {
1279                                         _DEBUG_INFO("parent node_acl null");
1280                                 }
1281
1282                                 parent_id = mo_parent_node->parent_id;
1283
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");
1288                                         break;
1289                                 }
1290
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);
1294
1295                                         dm_free_mo(mo_parent_node, 1);
1296                                         mo_parent_node = NULL;
1297
1298                                         return SYNC_AGENT_DM_MO_FAIL;
1299                                 }
1300                         }
1301                 }
1302         }
1303         _EXTERN_FUNC_EXIT;
1304         return SYNC_AGENT_DM_MO_SUCCESS;
1305 }
1306
1307 /*
1308  * check_acl = 0 : not permission acl
1309  * check_acl = 1 : not have accesstype
1310  * check_acl = 2 : permission acl
1311  */
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)
1313 {
1314         _EXTERN_FUNC_ENTER;
1315
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");
1318                 _EXTERN_FUNC_EXIT;
1319                 return SYNC_AGENT_DM_MO_FAIL;
1320         }
1321
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;
1330
1331         /* get acl value */
1332         err_code = dm_get_acl_value(mo_full_path, &mo_node);
1333         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1334                 *check_acl = 0;
1335                 goto return_part;
1336         }
1337
1338         if (mo_node == NULL) {
1339                 _DEBUG_INFO("command_str is NULL");
1340                 *check_acl = 0;
1341                 err_code = SYNC_AGENT_DM_MO_FAIL;
1342                 goto return_part;
1343         }
1344
1345         /*check accecctype error */
1346         _DEBUG_INFO("check accesstype : %d", access_type);
1347
1348         if (mo_node->framework_property != NULL) {
1349                 _DEBUG_INFO("framework accesstype : %d", mo_node->framework_property->accessType);
1350
1351                 if ((mo_node->framework_property->accessType != SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) && (mo_node->framework_property->accessType & access_type) != access_type) {
1352
1353                         *check_acl = 1;
1354                         goto return_part;
1355                 }
1356         }
1357
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");
1362                         *check_acl = 2;
1363                         err_code = SYNC_AGENT_DM_MO_SUCCESS;
1364                         goto return_part;
1365                 }
1366
1367                 mo_acl_value = iter->runtime_property->acl;
1368
1369                 _DEBUG_INFO("ALC : %s\n", mo_acl_value);
1370
1371                 if (isSearch_value == 2) {
1372                         isSearch_value = 1;
1373                         _DEBUG_INFO("acl ok \n");
1374                 } else {
1375                         _DEBUG_INFO("mo_acl_value = %s\n", mo_acl_value);
1376                         _DEBUG_INFO("access_type = %d\n", access_type);
1377
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");
1382                                 *check_acl = 0;
1383                                 err_code = SYNC_AGENT_DM_MO_FAIL;
1384                                 goto return_part;
1385                         }
1386
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;
1391
1392                                 _DEBUG_INFO("########## Operation Start ###########");
1393                                 _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd);
1394                                 ptr_cmd += strlen(command_str);
1395
1396                                 _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd);
1397                                 ptr_sev_id = strstr(ptr_cmd, "&");
1398
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);
1402                                 } else {
1403                                         _DEBUG_INFO("ptr_sev_id = %s\n", ptr_cmd);
1404                                         server_id_length = strlen(ptr_cmd);
1405                                 }
1406
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 !!!");
1411                                         *check_acl = 0;
1412                                         err_code = SYNC_AGENT_DM_MO_FAIL;
1413                                         goto return_part;
1414                                 }
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);
1418
1419                                 if (strcmp(mo_server_id, server_id) == 0) {
1420                                         _DEBUG_INFO("====> Search ACL Server_id");
1421                                         isSearch_value = 2;
1422
1423                                         if (mo_server_id != NULL) {
1424                                                 free(mo_server_id);
1425                                                 mo_server_id = NULL;
1426                                         }
1427
1428                                         break;
1429                                 } else if (strcmp(mo_server_id, "*") == 0) {
1430                                         _DEBUG_INFO("Exist All Format");
1431                                         isExist_all = 1;
1432                                 }
1433
1434                                 /* prepare next value check */
1435                                 if (ptr_sev_id != NULL) {
1436                                         ptr_cmd = strstr(ptr_sev_id, command_str);
1437                                 } else {
1438                                         ptr_cmd = NULL;
1439                                 }
1440
1441                                 if (mo_server_id != NULL) {
1442                                         free(mo_server_id);
1443                                         mo_server_id = NULL;
1444                                 }
1445                         }
1446                 }
1447         }
1448
1449
1450         if (mo_node != NULL)
1451                 dm_free_mo(mo_node, 1);
1452
1453         if (isSearch_value == 0) {
1454
1455                 if (isExist_all == 1) {
1456                         _DEBUG_INFO("##############################>>>>>> Search Value => exist * format !!");
1457                         *check_acl = 2;
1458
1459                         _EXTERN_FUNC_EXIT;
1460
1461                         return err_code;
1462                 } else {
1463                         _DEBUG_INFO("##############################>>>>>> Not Search Value ");
1464                         *check_acl = 0;
1465
1466                         _EXTERN_FUNC_EXIT;
1467
1468                         return err_code;
1469                 }
1470
1471         } else {
1472                 _DEBUG_INFO("##############################>>>>>> Search Value !!");
1473                 *check_acl = 2;
1474
1475                 _EXTERN_FUNC_EXIT;
1476
1477                 return err_code;
1478         }
1479
1480  return_part:
1481
1482         if (mo_node != NULL) {
1483                 dm_free_mo(mo_node, 1);
1484         }
1485
1486         _EXTERN_FUNC_EXIT;
1487         return err_code;
1488 }
1489
1490 EXPORT_API sync_agent_dm_mo_error_e sync_agent_create_mo_acc_item(sync_agent_dm_acc_info_s ** acc_info)
1491 {
1492         _EXTERN_FUNC_ENTER;
1493
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;
1497         }
1498
1499         _EXTERN_FUNC_EXIT;
1500
1501         return SYNC_AGENT_DM_MO_SUCCESS;
1502 }
1503
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)
1505 {
1506         _EXTERN_FUNC_ENTER;
1507
1508         sync_agent_dm_mo_error_e mo_error = SYNC_AGENT_DM_MO_SUCCESS;
1509
1510         const char *server_id_string = "ServerID";
1511         const char *acc_type_string = 0;
1512
1513         if (sync_agent_mo_acc_info_item == NULL) {
1514                 return SYNC_AGENT_DM_MO_FAIL;
1515         }
1516
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);
1519
1520         switch (sync_agent_mo_acc_info_item->acc_type) {
1521         case DEVICE_MANAGE_ACC_TYPE_SERVER:
1522                 acc_type_string = "/ServerAppAuth/";
1523                 break;
1524         case DEVICE_MANAGE_ACC_TYPE_CLIENT:
1525                 acc_type_string = "/ClientAppAuth/";
1526                 break;
1527         }
1528
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);
1531
1532         if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
1533                 _DEBUG_ERROR("Failed to dm_mo_get_acc_info_wraper()");
1534                 return mo_error;
1535         }
1536
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);
1544         } else {
1545                 _DEBUG_INFO("\nacc_info is NULL!!\n");
1546                 return SYNC_AGENT_DM_MO_FAIL;
1547         }
1548
1549         _EXTERN_FUNC_EXIT;
1550
1551         return mo_error;
1552 }
1553
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)
1555 {
1556         _EXTERN_FUNC_ENTER;
1557
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;
1561
1562         if (sync_agent_mo_acc_info_item == NULL) {
1563                 _EXTERN_FUNC_EXIT;
1564                 return SYNC_AGENT_DM_MO_FAIL;
1565         }
1566
1567         switch (sync_agent_mo_acc_info_item->acc_type) {
1568         case DEVICE_MANAGE_ACC_TYPE_SERVER:
1569                 acc_type_string = "/ServerAppAuth/";
1570                 break;
1571         case DEVICE_MANAGE_ACC_TYPE_CLIENT:
1572                 acc_type_string = "/ClientAppAuth/";
1573                 break;
1574         }
1575
1576         mo_error = dm_mo_set_acc_info_wraper(sync_agent_mo_acc_info_item->serverid, server_id_string, acc_type_string, acc_info);
1577
1578         if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
1579                 _DEBUG_ERROR("Failed to dm_mo_get_acc_info_wraper()");
1580                 return mo_error;
1581         }
1582
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);
1590         } else {
1591                 _DEBUG_INFO("\nacc_info is NULL!!\n");
1592         }
1593
1594         _EXTERN_FUNC_EXIT;
1595
1596         return mo_error;
1597 }
1598
1599 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_acc_item(sync_agent_dm_acc_info_s ** acc_info)
1600 {
1601         _EXTERN_FUNC_ENTER;
1602
1603         if ((*acc_info) != NULL) {
1604                 if ((*acc_info)->addr != NULL) {
1605                         free((*acc_info)->addr);
1606                         (*acc_info)->addr = NULL;
1607                 }
1608                 if ((*acc_info)->auth_data != NULL) {
1609                         free((*acc_info)->auth_data);
1610                         (*acc_info)->auth_data = NULL;
1611                 }
1612                 if ((*acc_info)->auth_level != NULL) {
1613                         free((*acc_info)->auth_level);
1614                         (*acc_info)->auth_level = NULL;
1615                 }
1616                 if ((*acc_info)->auth_name != NULL) {
1617                         free((*acc_info)->auth_name);
1618                         (*acc_info)->auth_name = NULL;
1619                 }
1620                 if ((*acc_info)->auth_secret != NULL) {
1621                         free((*acc_info)->auth_secret);
1622                         (*acc_info)->auth_secret = NULL;
1623                 }
1624                 if ((*acc_info)->auth_type != NULL) {
1625                         free((*acc_info)->auth_type);
1626                         (*acc_info)->auth_type = NULL;
1627                 }
1628                 (*acc_info) = NULL;
1629         }
1630
1631         _EXTERN_FUNC_EXIT;
1632
1633         return SYNC_AGENT_DM_MO_SUCCESS;
1634 }
1635
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)
1637 {
1638         _EXTERN_FUNC_ENTER;
1639
1640         retvm_if(mo_root == NULL, SYNC_AGENT_DM_MO_FAIL, "uptodate mo root NULL !!");
1641
1642         _DEBUG_INFO("mo_type : %d", mo_type);
1643
1644         sync_agent_dm_mo_node_s *root_node = NULL;
1645         int count = 0;
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);
1649
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);
1653
1654         sync_agent_traverse_mo_tree_preorder(root_node, _update_MO_info, 0, 0, (void **)(&func_point_get_value));
1655
1656         _EXTERN_FUNC_EXIT;
1657
1658         return SYNC_AGENT_DM_MO_SUCCESS;
1659 }
1660
1661 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_serverinfo(sync_agent_dm_server_info_s ** server_info)
1662 {
1663         _EXTERN_FUNC_ENTER;
1664
1665         sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
1666         const char *server_id_string = "ServerID";
1667
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);
1671                 return err;
1672         }
1673
1674         _DEBUG_INFO("get server id list result : %d", err);
1675         _EXTERN_FUNC_EXIT;
1676         return err;
1677 }
1678
1679 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_serverinfo(sync_agent_dm_server_info_s * server_info)
1680 {
1681         _EXTERN_FUNC_ENTER;
1682
1683         if (server_info != NULL) {
1684                 if (server_info->server_id != NULL) {
1685                         free(server_info->server_id);
1686                         server_info->server_id = NULL;
1687                 }
1688                 if (server_info->next != NULL) {
1689                         sync_agent_free_serverinfo(server_info->next);
1690                         server_info->next = NULL;
1691                 }
1692
1693                 free(server_info);
1694         }
1695
1696         _EXTERN_FUNC_EXIT;
1697
1698         return SYNC_AGENT_DM_MO_SUCCESS;
1699 }
1700
1701 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_serverid(sync_agent_dm_mo_type_e mo_type, char **server_id)
1702 {
1703         _EXTERN_FUNC_ENTER;
1704
1705         _DEBUG_INFO("mo_type : %d", mo_type);
1706
1707         const char *server_id_string = "ServerID";
1708
1709         sync_agent_dm_server_info_s *head_ptr = NULL;
1710         dm_mo_get_server_id_list_wraper(server_id_string, &head_ptr);
1711
1712         sync_agent_dm_server_info_s *cursor_ptr = head_ptr;
1713
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);
1717
1718                 int result = mo_type & (cursor_ptr->server_type);
1719
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;
1725                 }
1726
1727                 cursor_ptr = cursor_ptr->next;
1728         }
1729
1730         sync_agent_free_serverinfo(head_ptr);
1731         _EXTERN_FUNC_EXIT;
1732
1733         return SYNC_AGENT_DM_MO_FAIL;
1734 }
1735
1736 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_root_path(const char *mo_full_path, char **root_path)
1737 {
1738         _EXTERN_FUNC_ENTER;
1739
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;
1745         } else {
1746                 _DEBUG_INFO("Successed dm_mo_get_root_path_wraper() : [%s]", *root_path);
1747
1748         }
1749
1750         _EXTERN_FUNC_EXIT;
1751
1752         return SYNC_AGENT_DM_MO_SUCCESS;
1753 }
1754
1755 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_server_type(const char *server_id, int *server_type)
1756 {
1757         _EXTERN_FUNC_ENTER;
1758
1759         retvm_if((server_id) == NULL, SYNC_AGENT_DM_MO_FAIL, "server_id is NULL!!");
1760
1761         _DEBUG_INFO("server_id : %s", server_id);
1762         const char *server_id_string = "ServerID";
1763
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);
1767
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) {
1772                                 *server_type = 0;
1773                                 sync_agent_free_serverinfo(head_ptr);
1774                                 return SYNC_AGENT_DM_MO_SUCCESS;
1775                         }
1776                         _DEBUG_INFO("server_id : %s", cursor_ptr->server_id);
1777                         _DEBUG_INFO("server_type : %d", cursor_ptr->server_type);
1778
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;
1784                         }
1785                         cursor_ptr = cursor_ptr->next;
1786                 }
1787         } else {
1788
1789                 *server_type = 0;
1790                 sync_agent_free_serverinfo(head_ptr);
1791                 _EXTERN_FUNC_EXIT;
1792
1793                 return SYNC_AGENT_DM_MO_FAIL;
1794         }
1795
1796         *server_type = 0;
1797
1798         sync_agent_free_serverinfo(head_ptr);
1799         _EXTERN_FUNC_EXIT;
1800
1801         return SYNC_AGENT_DM_MO_SUCCESS;
1802 }
1803
1804 EXPORT_API sync_agent_dm_mo_error_e sync_agent_initialize_mo(int mo_plugin_id)
1805 {
1806         _EXTERN_FUNC_ENTER;
1807
1808         plugin_initialize func_point_initialize = NULL;
1809         func_point_initialize = plugin_get_function_initialize(mo_plugin_id);
1810
1811         if (func_point_initialize != NULL) {
1812                 int result = func_point_initialize();
1813                 if (result != 1) {
1814                         return SYNC_AGENT_DM_MO_FAIL;
1815                 }
1816         } else {
1817                 return SYNC_AGENT_DM_MO_FAIL;
1818         }
1819
1820         _EXTERN_FUNC_EXIT;
1821
1822         return SYNC_AGENT_DM_MO_SUCCESS;
1823 }
1824
1825 /******************************** static function implement **********************************/
1826
1827 int _update_MO_info(sync_agent_dm_mo_node_s * mo_node, int depth, void **arg)
1828 {
1829         _INNER_FUNC_ENTER;
1830
1831         if (mo_node == NULL) {
1832                 _DEBUG_TRACE("mo_node is NULL!!");
1833                 return -1;
1834         }
1835
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);
1839
1840         plugin_get_mo_value_cb func_point_get_value = (plugin_get_mo_value_cb) (*arg);
1841
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();");
1845
1846                 dm_update_mo(mo_node->mo_type, mo_node);
1847         }
1848
1849         _INNER_FUNC_EXIT;
1850
1851         return 0;
1852 }
1853
1854 /******************************************************** Impl static function *************************************************************/
1855
1856 static int _get_parent_path(const char *mo_pull_path, char **mo_parent_path, char **mo_name)
1857 {
1858         _INNER_FUNC_ENTER;
1859
1860         int mo_pull_path_len = strlen(mo_pull_path);
1861
1862         char *last_delimit = strrchr(mo_pull_path, DELIMIT);
1863
1864         /*
1865          * Is Root Node
1866          */
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 !!!");
1871                         return -1;
1872                 }
1873                 strncpy(*mo_name, mo_pull_path, mo_pull_path_len);
1874                 return 1;
1875         }
1876
1877         int name_len = strlen(last_delimit);
1878         int parent_path_len = mo_pull_path_len - name_len;
1879
1880         *mo_parent_path = (char *)calloc(parent_path_len + 1, sizeof(char));
1881         if (*mo_parent_path == NULL) {
1882                 _DEBUG_ERROR("CALLOC failed !!!");
1883                 return -1;
1884         }
1885         *mo_name = (char *)calloc(name_len, sizeof(char));
1886         if (*mo_name == NULL) {
1887                 _DEBUG_ERROR("CALLOC failed !!!");
1888                 return -1;
1889         }
1890
1891         strncpy(*mo_parent_path, mo_pull_path, parent_path_len);
1892         strncpy(*mo_name, last_delimit + 1, name_len);
1893
1894         _INNER_FUNC_EXIT;
1895
1896         return 0;
1897 }
1898
1899 static sync_agent_dm_mo_node_s *_create_default_mo_node(char *mo_full_path)
1900 {
1901         _INNER_FUNC_ENTER;
1902
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 !!!");
1906                 return NULL;
1907         }
1908
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);
1912         if (ret == -1) {
1913                 dm_free_mo(mo_node, 1);
1914
1915                 if (mo_parent_path != NULL)
1916                         free(mo_parent_path);
1917
1918                 return NULL;
1919         }
1920
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);
1924
1925 /*      if (mo_parent_path != NULL) {
1926                 free(mo_parent_path);
1927         }*/
1928         mo_node->id = -1;
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;
1933
1934         if (mo_parent_path == NULL) {
1935                 mo_node->type = SYNC_AGENT_DM_MO_NODE_ROOT;
1936                 _DEBUG_TRACE("------------------root node-----------------");
1937         } else {
1938                 mo_node->type = SYNC_AGENT_DM_MO_NODE_INTERIOR;
1939         }
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);
1946
1947                 return NULL;
1948         }
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);
1955
1956                 return NULL;
1957         }
1958
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);
1966         }
1967
1968         if (mo_parent_path != NULL)
1969                 free(mo_parent_path);
1970
1971         _INNER_FUNC_EXIT;
1972
1973         return mo_node;
1974 }
1975
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)
1977 {
1978         _INNER_FUNC_ENTER;
1979
1980         int count = 0;
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) {
1985                 return err_code;
1986         }
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);
1992
1993         if (mo_path) {
1994                 int i = 0;
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) {
2000                                 break;
2001                         }
2002                 }
2003         } else {
2004                 return SYNC_AGENT_DM_MO_FAIL;
2005         }
2006
2007         _INNER_FUNC_EXIT;
2008
2009         return err_code;
2010 }
2011
2012 static char *_get_access_type_string(sync_agent_dm_mo_access_type_e access_type)
2013 {
2014         _INNER_FUNC_ENTER;
2015
2016         char *command_str = NULL;
2017
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=";
2023                 break;
2024         case SYNC_AGENT_DM_MO_ACCESSTYPE_COPY:
2025                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_COPY");
2026                 command_str = "Copy=";
2027                 break;
2028         case SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE:
2029                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE");
2030                 command_str = "Delete=";
2031                 break;
2032         case SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC:
2033                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC");
2034                 command_str = "Exec=";
2035                 break;
2036         case SYNC_AGENT_DM_MO_ACCESSTYPE_GET:
2037                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_GET");
2038                 command_str = "Get=";
2039                 break;
2040         case SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE:
2041                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE");
2042                 command_str = "Replace=";
2043                 break;
2044         default:
2045                 _DEBUG_TRACE("can not execute logic");
2046                 break;
2047         }
2048         _DEBUG_TRACE("command string = %s\n", command_str);
2049
2050         _INNER_FUNC_EXIT;
2051
2052         return command_str;
2053 }
2054
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)
2056 {
2057         _INNER_FUNC_ENTER;
2058
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;
2062         }
2063
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;
2066
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;
2070
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);
2073
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);
2077         }
2078
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);
2082         }
2083
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);
2088         }
2089
2090         /* set version No, size */
2091         runtime_property->verNo = strdup("0");
2092         runtime_property->size = 0;
2093
2094         /* set stamp */
2095         SYNC_AGENT_UTIL_TIME_T current_time;
2096         SYNC_AGENT_UTIL_TIME(&current_time);
2097
2098         SYNC_AGENT_UTIL_TM *time;
2099         time = SYNC_AGENT_UTIL_LOCALTIME(&current_time);
2100
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);
2102
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);
2105
2106         /* set ACL */
2107         if (runtime_property->acl != NULL) {
2108                 /*aready this is setted runtime property acl */
2109                 _INNER_FUNC_EXIT;
2110                 return SYNC_AGENT_DM_MO_SUCCESS;
2111         }
2112
2113         int total_acl_size = 0;
2114         if (server_id_list_cnt > 0) {
2115
2116                 int i, j;
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;
2121                         }
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]));
2124                 }
2125
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;
2130                 }
2131                 int total_acl_value_idx = 0;
2132
2133                 sync_agent_dm_mo_access_type_e access_type = SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET;
2134                 char *command_str = NULL;
2135
2136                 int temp_acl_value_size = 0;
2137                 char *temp_acl_value = NULL;
2138
2139                 int mul = 1;
2140                 for (i = 1; i <= DEVICE_MANAGER_MO_ACCESSTYPE_CNT; i++) {
2141
2142                         _DEBUG_VERBOSE("framework_property->accessType = %d\n", framework_property->accessType);
2143                         if (framework_property->accessType != SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) {
2144
2145                                 access_type = framework_property->accessType & (mul);
2146                                 _DEBUG_VERBOSE("accessType = %d\n", access_type);
2147                                 command_str = _get_access_type_string(access_type);
2148
2149                                 if (command_str != NULL) {
2150                                         for (j = 0; j < server_id_list_cnt; j++) {
2151
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]);
2155                                                 } else {
2156                                                         temp_acl_value = g_strdup_printf("%s%s&", command_str, server_id_list[j]);
2157                                                 }
2158
2159                                                 temp_acl_value_size = strlen(temp_acl_value);
2160
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;
2164                                         }
2165                                 }
2166                         } else {
2167                                 break;
2168                         }
2169
2170                         mul *= 2;
2171                 }
2172
2173                 _DEBUG_VERBOSE("total_acl_value = %s\n", total_acl_value);
2174                 runtime_property->acl = total_acl_value;
2175         }
2176
2177         _INNER_FUNC_EXIT;
2178
2179         return SYNC_AGENT_DM_MO_SUCCESS;
2180 }
2181
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)
2183 {
2184         _INNER_FUNC_ENTER;
2185
2186         sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
2187
2188         if (mo_node == NULL) {
2189                 return SYNC_AGENT_DM_MO_FAIL;
2190         }
2191
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("================================================================================");
2196
2197         /*
2198          * Setting acl of RuntimeProperty in PlugIn
2199          */
2200
2201         /*
2202          * Set MO Value from PlugIn
2203          */
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);
2207         }
2208
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);
2213                 return err;
2214         }
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);
2218                 return err;
2219         }
2220
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);
2225                 return err;
2226         }
2227
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);
2232                 return err;
2233         }
2234
2235         sync_agent_dm_mo_node_s *pCursor = mo_node->child_node_list;
2236         while (pCursor != NULL) {
2237                 pCursor->parent_id = mo_node->id;
2238
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) {
2241                         return err;
2242                 }
2243
2244                 pCursor = pCursor->next_node;
2245         }
2246
2247         _INNER_FUNC_EXIT;
2248
2249         return err;
2250 }
2251
2252 /*
2253 static void __print_Tree(sync_agent_dm_mo_node_s * root_ptr, int depth)
2254 {
2255         if (root_ptr == NULL) {
2256                 return;
2257         }
2258 //      int i = 0;
2259 //      for ( ; i < depth; i++) {
2260 //              _DEBUG_INFO("\t");
2261 //      }
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("================================================================================");
2265
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;
2270         }
2271 }
2272 */