Remove hardcoded path for multiuser support
[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 #include <tzplatform_config.h>
36
37 #ifndef EXPORT_API
38 #define EXPORT_API __attribute__ ((visibility("default")))
39 #endif
40
41 #ifndef SYNC_AGENT_LOG
42 #undef LOG_TAG
43 #define LOG_TAG "AF_MO"
44 #endif
45
46 #define DELIMIT '/'
47
48 static int _get_parent_path(const char *mo_pull_path, char **mo_parent_path, char **mo_name);
49
50 static sync_agent_dm_mo_node_s *_create_default_mo_node(char *mo_full_path);
51
52 static sync_agent_dm_mo_error_e _recursive_get_Descendant_MO_List(sync_agent_dm_mo_type_e type, const char *mo_path, sync_agent_dm_mo_node_s * parent_node, int *count, sync_agent_dm_mo_get_option_e option);
53
54 static char *_get_access_type_string(sync_agent_dm_mo_access_type_e access_type);
55
56 static sync_agent_dm_mo_error_e __set_MO_RunTimeProperty(char **server_id_list, int server_id_list_cnt, sync_agent_dm_mo_node_s * mo_node);
57
58 static sync_agent_dm_mo_error_e _add_MO_Tree(sync_agent_dm_mo_type_e mo_type, sync_agent_dm_mo_node_s * mo_node, plugin_get_mo_value_cb func_point_get_value, char **server_id_list, int server_id_list_cnt, int server_type);
59
60 /* static void __print_Tree(sync_agent_dm_mo_node_s * root_ptr, int depth); // to Debugging */
61
62 static int _update_MO_info(sync_agent_dm_mo_node_s * mo_node, int depth, void **arg);
63
64 EXPORT_API sync_agent_dm_mo_error_e sync_agent_open_mo()
65 {
66         _EXTERN_FUNC_ENTER;
67
68         _EXTERN_FUNC_EXIT;
69
70         return dm_mo_open((char*)tzplatform_mkpath(TZ_USER_DB,".momanager.db"));
71 }
72
73 EXPORT_API sync_agent_dm_mo_error_e sync_agent_close_mo()
74 {
75         _EXTERN_FUNC_ENTER;
76
77         _EXTERN_FUNC_EXIT;
78
79         return dm_mo_close();
80 }
81
82 EXPORT_API sync_agent_dm_mo_error_e sync_agent_construct_mo_table(sync_agent_dm_mo_type_e mo_type, const char *vendar_file, int mo_plugin_id, int server_type)
83 {
84         _EXTERN_FUNC_ENTER;
85
86         retvm_if(vendar_file == NULL, SYNC_AGENT_DM_MO_FAIL, "vendar_file is NULL !!");
87
88         _DEBUG_INFO("vender_file = %s", vendar_file);
89         char *root_node_path = strdup(".");
90
91         sync_agent_dm_mo_node_s *root_node = _create_default_mo_node(root_node_path);
92         if (root_node == NULL) {
93                 _DEBUG_INFO("root node null");
94                 return SYNC_AGENT_DM_MO_FAIL;
95         }
96         sync_agent_dm_mo_error_e err_code = dm_mo_construct_mo_tree_ddf(mo_type, vendar_file, root_node);
97         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
98                 return err_code;
99         }
100
101         plugin_get_mo_value_cb func_point_get_value = NULL;
102         func_point_get_value = plugin_get_function_get_mo_value(mo_plugin_id);
103
104         plugin_get_server_id_list_cb func_point_get_server_id_list = NULL;
105         func_point_get_server_id_list = plugin_get_function_get_server_id_list(mo_plugin_id);
106
107         retvm_if(func_point_get_server_id_list == NULL, SYNC_AGENT_DM_MO_FAIL, "cannot get plugin_get_server_id_list_cb !!");
108
109         char **server_id_list = NULL;
110         int server_id_list_cnt = 0;
111         server_id_list = func_point_get_server_id_list(&server_id_list_cnt);
112         _DEBUG_INFO("server_id_list_cnt = %d", server_id_list_cnt);
113
114         err_code = sync_agent_begin_transaction_mo();
115
116         err_code = _add_MO_Tree(mo_type, root_node, func_point_get_value, server_id_list, server_id_list_cnt, server_type);
117
118         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
119                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
120         } else {
121                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
122         }
123
124         _EXTERN_FUNC_EXIT;
125
126         return err_code;
127 }
128
129 EXPORT_API sync_agent_dm_mo_error_e sync_agent_begin_transaction_mo()
130 {
131         _EXTERN_FUNC_ENTER;
132
133         _EXTERN_FUNC_EXIT;
134
135         return dm_mo_begin_transaction_wraper();
136 }
137
138 EXPORT_API sync_agent_dm_mo_error_e sync_agent_end_transaction_mo(sync_agent_dm_mo_transaction_e transaction)
139 {
140         _EXTERN_FUNC_ENTER;
141
142         sync_agent_da_transaction_e transation_option;
143
144         if (transaction == SYNC_AGENT_DM_MO_TRANSACTION_COMMIT) {
145                 transation_option = SYNC_AGENT_DA_TRANSACTION_COMMIT;
146         } else {
147                 transation_option = SYNC_AGENT_DA_TRANSACTION_ROLLBACK;
148         }
149
150         _EXTERN_FUNC_EXIT;
151
152         return dm_mo_end_transaction_wraper(transation_option);
153 }
154
155 sync_agent_dm_mo_error_e dm_create_mo(sync_agent_dm_mo_node_s ** sync_agent_dm_mo_node)
156 {
157         _EXTERN_FUNC_ENTER;
158
159         *sync_agent_dm_mo_node = (sync_agent_dm_mo_node_s *) calloc(1, sizeof(sync_agent_dm_mo_node_s));
160         if (*sync_agent_dm_mo_node == NULL) {
161                 return SYNC_AGENT_DM_MO_FAIL;
162         }
163         (*sync_agent_dm_mo_node)->framework_property = (sync_agent_dm_mo_framework_property_s *) calloc(1, sizeof(sync_agent_dm_mo_framework_property_s));
164         if ((*sync_agent_dm_mo_node)->framework_property == NULL) {
165                 return SYNC_AGENT_DM_MO_FAIL;
166         }
167         (*sync_agent_dm_mo_node)->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
168         if ((*sync_agent_dm_mo_node)->runtime_property == NULL) {
169                 return SYNC_AGENT_DM_MO_FAIL;
170         }
171
172         _EXTERN_FUNC_EXIT;
173
174         return SYNC_AGENT_DM_MO_SUCCESS;
175 }
176
177 EXPORT_API sync_agent_dm_mo_error_e sync_agent_create_mo_item(sync_agent_dm_mo_node_s ** sync_agent_mo_item)
178 {
179         _EXTERN_FUNC_ENTER;
180
181         _EXTERN_FUNC_EXIT;
182
183         return dm_create_mo(sync_agent_mo_item);
184 }
185
186 EXPORT_API sync_agent_dm_mo_error_e sync_agent_add_mo_item(sync_agent_dm_mo_node_s * sync_agent_mo_item)
187 {
188         _EXTERN_FUNC_ENTER;
189
190         retvm_if(sync_agent_mo_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
191
192         _EXTERN_FUNC_EXIT;
193
194         return dm_add_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path, sync_agent_mo_item);
195 }
196
197 EXPORT_API sync_agent_dm_mo_error_e sync_agent_update_mo_item(sync_agent_dm_mo_node_s * sync_agent_item)
198 {
199         _EXTERN_FUNC_ENTER;
200
201         retvm_if(sync_agent_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
202
203         _EXTERN_FUNC_EXIT;
204
205         return dm_update_mo(sync_agent_item->mo_type, sync_agent_item);
206 }
207
208 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_mo_item(const char *mo_path)
209 {
210         _EXTERN_FUNC_ENTER;
211
212         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
213
214         sync_agent_dm_mo_type_e mo_type = dm_mo_get_mo_type_wraper(mo_path);
215
216         _EXTERN_FUNC_EXIT;
217
218         return dm_delete_mo(mo_type, mo_path);
219 }
220
221 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_mo_tree_item(const char *mo_path)
222 {
223         _EXTERN_FUNC_ENTER;
224
225         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
226
227         _EXTERN_FUNC_EXIT;
228
229         return dm_delete_mo_tree(mo_path);
230 }
231
232 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_mo_item(const char *mo_path, sync_agent_dm_mo_node_s ** sync_agent_mo_item)
233 {
234         _EXTERN_FUNC_ENTER;
235
236         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
237
238         _EXTERN_FUNC_EXIT;
239
240         return dm_get_mo(mo_path, sync_agent_mo_item, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
241 }
242
243 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_mo_items(const char *mo_path, sync_agent_dm_mo_node_s ** sync_agent_mo_item)
244 {
245         _EXTERN_FUNC_ENTER;
246
247         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
248
249         _EXTERN_FUNC_EXIT;
250
251         return dm_get_mos(mo_path, sync_agent_mo_item, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
252 }
253
254 EXPORT_API sync_agent_dm_mo_error_e sync_agent_query_mo_item(sync_agent_dm_mo_item_s * sync_agent_mo_item, GList ** list)
255 {
256         _EXTERN_FUNC_ENTER;
257
258         retvm_if(sync_agent_mo_item == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_item_s is NULL !!");
259
260         sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
261         int count = 0;
262         sync_agent_dm_mo_node_s *mo_node_list = NULL;
263
264         if (sync_agent_mo_item->interface_type == MO_ITEM_CHILD_MO_VALUE_LIST) {
265
266                 retvm_if(sync_agent_mo_item->mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
267
268                 _DEBUG_INFO("mo full path  : %s", sync_agent_mo_item->mo_path);
269                 ret = dm_get_child_mo_list(sync_agent_mo_item->mo_type, sync_agent_mo_item->mo_path, &mo_node_list, &count, sync_agent_mo_item->option);
270                 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
271                         return SYNC_AGENT_DM_MO_FAIL;
272                 }
273                 _DEBUG_INFO("get child mo list count : %d", count);
274
275                 int i;
276                 for (i = 0; i < count; ++i) {
277                         *list = g_list_append(*list, &(mo_node_list[i]));
278                 }
279
280                 return SYNC_AGENT_DM_MO_SUCCESS;
281
282         } else if (sync_agent_mo_item->interface_type == MO_ONLY_DATA_VALUE) {
283                 ret = dm_get_mo(sync_agent_mo_item->mo_path, &mo_node_list, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
284                 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
285                         return SYNC_AGENT_DM_MO_FAIL;
286                 }
287
288                 *list = g_list_append(*list, mo_node_list);
289
290                 return SYNC_AGENT_DM_MO_SUCCESS;
291         } else if (sync_agent_mo_item->interface_type == MO_ALL_VALUE) {
292                 ret = dm_get_mo(sync_agent_mo_item->mo_path, &mo_node_list, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
293                 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
294                         return SYNC_AGENT_DM_MO_FAIL;
295                 }
296
297                 *list = g_list_append(*list, mo_node_list);
298
299                 return SYNC_AGENT_DM_MO_SUCCESS;
300         }
301
302         _EXTERN_FUNC_EXIT;
303
304         return SYNC_AGENT_DM_MO_FAIL;
305 }
306
307 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_item(sync_agent_dm_mo_node_s * sync_agent_mo_item)
308 {
309         _EXTERN_FUNC_ENTER;
310
311         if (sync_agent_mo_item != NULL) {
312                 dm_free_mo(sync_agent_mo_item, 1);
313         }
314
315         _EXTERN_FUNC_EXIT;
316
317         return SYNC_AGENT_DM_MO_SUCCESS;
318 }
319
320 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_item_list(GList * list)
321 {
322         _EXTERN_FUNC_ENTER;
323
324         retvm_if(list == NULL, SYNC_AGENT_DM_MO_FAIL, "list is NULL !!");
325
326         int count = 0;
327         count = g_list_length(list);
328         _DEBUG_INFO(" mo list length : %d", count);
329         dm_free_mo(list->data, count);
330
331         g_list_free(list);
332
333         _EXTERN_FUNC_EXIT;
334
335         return SYNC_AGENT_DM_MO_FAIL;
336 }
337
338 sync_agent_dm_mo_error_e dm_add_mo(sync_agent_dm_mo_type_e mo_type, const char *mo_full_path, sync_agent_dm_mo_node_s * mo_node)
339 {
340         _EXTERN_FUNC_ENTER;
341
342         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
343         retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
344
345         sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
346
347         _DEBUG_INFO("===============================================");
348         _DEBUG_INFO("sync_agent_dm_mo_type_e  : %d", mo_type);
349         _DEBUG_INFO("mo_full_path  : %s", mo_full_path);
350         _DEBUG_INFO("mo_value  : %s", mo_node->value);
351         _DEBUG_INFO("node type  : %d", mo_node->type);
352         _DEBUG_INFO("===============================================");
353
354         /*
355          * Get Parent Node from MO DB using by mo_parent_path
356          */
357         char *mo_parent_path = NULL;
358         char *mo_name = NULL;
359         int isRootNode = _get_parent_path(mo_full_path, &mo_parent_path, &mo_name);
360         if (isRootNode == -1) {
361                 if (mo_parent_path != NULL)
362                         free(mo_parent_path);
363                 return SYNC_AGENT_DM_MO_FAIL;
364         }
365
366         if (isRootNode) {
367                 _DEBUG_INFO("is root node");
368                 /*
369                  * Add MO Node to MO DB
370                  */
371                 err = dm_mo_add_node_wraper(SYNC_AGENT_DM_MO_TYPE_NO_TYPE, mo_node);
372                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
373                         _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
374                         if (mo_name != NULL)
375                                 free(mo_name);
376                         return err;
377                 }
378
379                 /*
380                  * Add MO Properties to MO DB
381                  */
382                 if (mo_node->framework_property != NULL) {
383                         _DEBUG_INFO("add frameowork_property");
384                         err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
385                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
386                                 _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
387                         }
388                 }
389
390                 if (mo_node->runtime_property != NULL) {
391                         _DEBUG_INFO("add runtime_property");
392                         err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
393                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
394                                 _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
395                         }
396                 }
397
398                 if (mo_name != NULL)
399                         free(mo_name);
400
401                 return SYNC_AGENT_DM_MO_SUCCESS;
402         }
403
404         _DEBUG_INFO("mo_parent_path : %s", mo_parent_path);
405         _DEBUG_INFO("mo_name : %s", mo_name);
406
407         sync_agent_dm_mo_node_s *mo_parent_node = NULL;
408         sync_agent_dm_mo_node_s *real_mo_parent_node = NULL;
409         err = dm_get_mos(mo_parent_path, &mo_parent_node, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
410         _DEBUG_INFO("get mo : %d", err);
411
412         real_mo_parent_node = mo_parent_node;
413         if (real_mo_parent_node == NULL) {
414                 /*
415                  * Create Parent MO Node (Default MO Node)
416                  */
417                 _DEBUG_INFO("parent node empty");
418                 real_mo_parent_node = _create_default_mo_node(mo_parent_path);
419
420                 err = dm_add_mo(SYNC_AGENT_DM_MO_TYPE_NO_TYPE, mo_parent_path, real_mo_parent_node);
421                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
422                         if (mo_name != NULL)
423                                 free(mo_name);
424                         return err;
425                 }
426         } else {
427                 while (real_mo_parent_node != NULL) {
428                         _DEBUG_INFO("parent_node id : %d", real_mo_parent_node->id);
429                         _DEBUG_INFO("parent_node mo type : %d", real_mo_parent_node->mo_type);
430                         _DEBUG_INFO("parent_node server type : %d", real_mo_parent_node->server_type);
431                         _DEBUG_INFO("mo server type : %d", mo_node->server_type);
432
433                         if (real_mo_parent_node->server_type == mo_node->server_type) {
434                                 _DEBUG_INFO("mo server type : %d", mo_node->server_type);
435                                 break;
436                         }
437                         _DEBUG_INFO("this node is not parent node");
438                         real_mo_parent_node = real_mo_parent_node->next_node;
439                 }
440
441                 if (real_mo_parent_node == NULL) {
442                         real_mo_parent_node = mo_parent_node;
443                 }
444         }
445
446         mo_node->name = mo_name;
447         mo_node->parent_id = real_mo_parent_node->id;
448         mo_node->mo_type = real_mo_parent_node->mo_type;
449
450         _DEBUG_INFO("mo_name : %s", mo_node->name);
451         _DEBUG_INFO("mo_parent_id : %d", mo_node->parent_id);
452         _DEBUG_INFO("node type : %d", mo_node->type);
453         _DEBUG_INFO("mo type : %d", mo_node->mo_type);
454
455         /*
456          * Add MO Node to MO DB
457          */
458         err = dm_mo_add_node_wraper(mo_node->mo_type, mo_node);
459         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
460                 _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
461                 dm_free_mo(mo_parent_node, 1);
462                 return err;
463         }
464
465         /*
466          * Add MO Properties to MO DB
467          */
468         if (mo_node->framework_property != NULL) {
469                 _DEBUG_INFO("add frameowork_property  %d", mo_node->id);
470                 err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
471                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
472                         _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
473                 }
474         }
475
476         if (mo_node->runtime_property != NULL) {
477                 _DEBUG_INFO("add runtime_property %d", mo_node->id);
478                 err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
479                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
480                         _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
481                 }
482         }
483
484         _DEBUG_INFO("mo_parent_node->id : %d", real_mo_parent_node->id);
485         _DEBUG_INFO("mo_node->id : %d", mo_node->id);
486         _DEBUG_INFO("================================================");
487
488         dm_free_mo(mo_parent_node, 1);
489
490         _EXTERN_FUNC_EXIT;
491
492         return SYNC_AGENT_DM_MO_SUCCESS;
493 }
494
495 sync_agent_dm_mo_error_e dm_delete_mo(sync_agent_dm_mo_type_e type, const char *mo_full_path)
496 {
497         _EXTERN_FUNC_ENTER;
498
499         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
500
501         _DEBUG_INFO("mo_full_path  : %s", mo_full_path);
502
503         sync_agent_dm_mo_node_s *target_node = NULL;
504         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
505
506         err_code = dm_get_mo(mo_full_path, &target_node, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
507         _DEBUG_INFO("get mo : %d", err_code);
508         if (target_node == NULL) {
509                 _DEBUG_INFO("MO is not existed [%s]", mo_full_path);
510                 return SYNC_AGENT_DM_MO_SUCCESS;
511         }
512
513         /*
514          * Delete All Child Nodes(Recursive)
515          */
516         if (target_node->type == SYNC_AGENT_DM_MO_NODE_INTERIOR || target_node->type == SYNC_AGENT_DM_MO_NODE_ROOT || target_node->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
517                 /*
518                  * Get all right Child Node list
519                  */
520                 sync_agent_dm_mo_node_s *child_node_list = NULL;
521                 int child_node_count = 0;
522                 err_code = dm_get_child_mo_list(type, mo_full_path, &child_node_list, &child_node_count, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
523                 _DEBUG_INFO("get child mo list result  : %d", err_code);
524                 _DEBUG_INFO("child_node_count  : %d", child_node_count);
525
526                 if (child_node_list != NULL) {
527                         int i = 0;
528                         for (; i < child_node_count; i++) {
529                                 char *child_node_path = child_node_list[i].full_path;
530                                 err_code = dm_delete_mo(type, child_node_path);
531                                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
532                                         _DEBUG_ERROR("delete mo tree: [%d]", err_code);
533                                         dm_free_mo(target_node, 1);
534
535                                         dm_free_mo(child_node_list, child_node_count);
536
537                                         return SYNC_AGENT_DM_MO_FAIL;
538                                 }
539                         }
540                 }
541
542                 dm_free_mo(child_node_list, child_node_count);
543         } else {
544                 _DEBUG_INFO("leaf node");
545         }
546
547         /*
548          * Delete sync_agent_dm_mo_node_s, MO Properties In MO DB using by mo_node_id
549          */
550         _DEBUG_INFO("target_node->id : %d", target_node->id);
551
552         err_code = dm_mo_delete_node_wraper(target_node->id);
553         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
554                 _DEBUG_ERROR("Failed to call dm_mo_delete_node_wraper [%d]", err_code);
555         }
556
557         err_code = dm_mo_delete_runtime_property_wraper(target_node->id);
558         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
559                 _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err_code);
560         }
561
562         err_code = dm_mo_delete_framework_property_wraper(target_node->id);
563         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
564                 _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err_code);
565         }
566
567         dm_free_mo(target_node, 1);
568
569         _EXTERN_FUNC_EXIT;
570
571         return SYNC_AGENT_DM_MO_SUCCESS;
572 }
573
574 sync_agent_dm_mo_error_e dm_delete_mo_tree(const char *mo_path)
575 {
576         _EXTERN_FUNC_ENTER;
577
578         sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_FAIL;
579         sync_agent_dm_mo_node_s *sync_agent_mo_item = NULL;
580         sync_agent_dm_mo_node_s *mo_parent_node = NULL;
581         int is_exist = 0;
582
583         err = sync_agent_is_exist_mo(mo_path, &is_exist);
584         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
585                 _DEBUG_ERROR("remove dm_acc fail, is existed mo fail");
586                 _EXTERN_FUNC_EXIT;
587                 return SYNC_AGENT_DM_MO_FAIL;
588         }
589
590         if (is_exist != 1) {
591                 _DEBUG_ERROR("remove dm_acc fail because dm acc %s not existed", mo_path);
592                 _EXTERN_FUNC_EXIT;
593                 return SYNC_AGENT_DM_MO_NOT_EXIST_NODE;
594         }
595
596         err = sync_agent_get_mo_items(mo_path, &sync_agent_mo_item);
597         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
598                 _DEBUG_ERROR("remove dm_acc fail, get mo ite fail");
599
600                 if(sync_agent_mo_item != NULL) {
601                         err = sync_agent_free_mo_item(sync_agent_mo_item);
602                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
603                                 _DEBUG_ERROR("free mo  tree: [%d]", err);
604                         } else {
605                                 _DEBUG_INFO("free mo success");
606                         }
607                 }
608
609                 _EXTERN_FUNC_EXIT;
610                 return SYNC_AGENT_DM_MO_FAIL;
611         }
612
613         if (sync_agent_mo_item->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
614
615                 /*first node */
616                 sync_agent_dm_mo_node_s *iter = NULL;
617                 int i = 0;
618
619                 err = dm_delete_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path);
620                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
621                         _DEBUG_ERROR("free mo tree: [%d]", err);
622                 }
623
624                 for (iter = sync_agent_mo_item; iter != NULL; iter = iter->next_node, i++) {
625                         _DEBUG_INFO("mo_node id : %d", iter->id);
626
627                         _DEBUG_INFO("prent id : %d ", iter->parent_id);
628                         err = dm_mo_delete_node_wraper(iter->parent_id);
629                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
630                                 _DEBUG_ERROR("delete mo  tree: [%d]", err);
631                                 goto error;
632                         }
633
634                         err = dm_mo_delete_runtime_property_wraper(iter->parent_id);
635                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
636                                 _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err);
637                                 goto error;
638                         }
639
640                         err = dm_mo_delete_framework_property_wraper(iter->parent_id);
641                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
642                                 _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err);
643                                 goto error;
644                         }
645                 }
646
647         } else if (sync_agent_mo_item->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
648
649                 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DMACC, sync_agent_mo_item->full_path);
650                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
651                         _DEBUG_ERROR("delete mo tree: [%d]", err);
652                         goto error;
653                 }
654                 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DEVINFO, sync_agent_mo_item->full_path);
655                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
656                         _DEBUG_ERROR("delete mo tree: [%d]", err);
657                         goto error;
658                 }
659                 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_DEVDETAIL, sync_agent_mo_item->full_path);
660                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
661                         _DEBUG_ERROR("delete mo tree: [%d]", err);
662                         goto error;
663                 }
664                 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_FUMO, sync_agent_mo_item->full_path);
665                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
666                         _DEBUG_ERROR("delete mo tree: [%d]", err);
667                         goto error;
668                 }
669                 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_LAWMO, sync_agent_mo_item->full_path);
670                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
671                         _DEBUG_ERROR("delete mo tree: [%d]", err);
672                         goto error;
673                 }
674                 err = dm_delete_mo(SYNC_AGENT_DM_MO_TYPE_SCOMO, sync_agent_mo_item->full_path);
675                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
676                         _DEBUG_ERROR("delete mo tree: [%d]", err);
677                         goto error;
678                 }
679
680         } else {
681                 /*not root node, first node */
682
683                 err = dm_delete_mo(sync_agent_mo_item->mo_type, sync_agent_mo_item->full_path);
684                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
685                         _DEBUG_ERROR("delete mo tree: [%d]", err);
686                         goto error;
687                 }
688
689                 _DEBUG_INFO("prent id : %d ", sync_agent_mo_item->parent_id);
690                 err = dm_mo_get_node_from_id_wraper(sync_agent_mo_item->parent_id, &mo_parent_node);
691                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
692                         _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err);
693                         goto error;
694                 }
695
696                 while (1) {
697
698                         int parent_id = 0;
699                         parent_id = mo_parent_node->parent_id;
700
701                         if (mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_ROOT || mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_FIRST) {
702
703                                 err = dm_mo_delete_node_wraper(mo_parent_node->id);
704                                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
705                                         _DEBUG_ERROR("delete mo  tree: [%d]", err);
706                                         goto error;
707                                 }
708
709                                 err = dm_mo_delete_runtime_property_wraper(mo_parent_node->id);
710                                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
711                                         _DEBUG_ERROR("Failed to call dm_mo_delete_runtime_property_wraper [%d]", err);
712                                         goto error;
713                                 }
714
715                                 err = dm_mo_delete_framework_property_wraper(mo_parent_node->id);
716                                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
717                                         _DEBUG_ERROR("Failed to call dm_mo_delete_framework_property_wraper [%d]", err);
718                                         goto error;
719                                 }
720
721                                 if (mo_parent_node->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
722                                         err = sync_agent_free_mo_item(mo_parent_node);
723                                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
724                                                 _DEBUG_ERROR("free mo  tree: [%d]", err);
725                                                 goto error;
726                                         } else {
727                                                 _DEBUG_INFO("free mo success");
728                                         }
729
730                                         break;
731                                 }
732
733                         } else {
734                                 _DEBUG_INFO("first node path : %s", mo_parent_node->full_path);
735                                 err = dm_delete_mo(mo_parent_node->mo_type, mo_parent_node->full_path);
736                                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
737                                         _DEBUG_ERROR("free mo tree: [%d]", err);
738                                         goto error;
739                                 }
740                         }
741
742                         err = sync_agent_free_mo_item(mo_parent_node);
743                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
744                                 _DEBUG_ERROR("free mo  tree: [%d]", err);
745                                 goto error;
746                         } else {
747                                 _DEBUG_INFO("free mo success");
748                         }
749
750                         mo_parent_node = NULL;
751
752                         _DEBUG_INFO("prent id : %d ", parent_id);
753                         err = dm_mo_get_node_from_id_wraper(parent_id, &mo_parent_node);
754                         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
755                                 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err);
756                                 goto error;
757                         }
758                 }
759         }
760
761         err = sync_agent_free_mo_item(sync_agent_mo_item);
762         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
763                 _DEBUG_ERROR("free mo  tree: [%d]", err);
764                 goto error;
765         } else {
766                 _DEBUG_INFO("free mo success");
767         }
768
769         _EXTERN_FUNC_EXIT;
770         return err;
771
772  error:
773
774         err = sync_agent_free_mo_item(sync_agent_mo_item);
775         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
776                 _DEBUG_ERROR("free mo  tree: [%d]", err);
777         } else {
778                 _DEBUG_INFO("free mo success");
779         }
780
781         if(mo_parent_node != NULL) {
782                 free(mo_parent_node);
783                 mo_parent_node = NULL;
784         }
785
786         _EXTERN_FUNC_EXIT;
787         return err;
788 }
789
790 sync_agent_dm_mo_error_e dm_update_mo(sync_agent_dm_mo_type_e type, const sync_agent_dm_mo_node_s * mo_node)
791 {
792         _EXTERN_FUNC_ENTER;
793
794         retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
795
796         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
797
798         _DEBUG_INFO("sync_agent_dm_mo_type_e  : %d", type);
799         _DEBUG_INFO("node_id  : %d", mo_node->id);
800         _DEBUG_INFO("will be updated full_path  : %s", mo_node->full_path);
801
802         /*
803          * Update MO Node tbl
804          */
805         err_code = dm_mo_update_node_wraper(type, mo_node->full_path, mo_node);
806
807         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
808                 _DEBUG_ERROR("Failed dm_mo_update_node_wraper() : %d", err_code);
809                 return err_code;
810         }
811
812         /*
813          * Update Framework property tbl
814          */
815         if (mo_node->framework_property != NULL) {
816                 err_code = dm_mo_update_framework_property_wraper(mo_node->id, mo_node->framework_property);
817                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
818                         _DEBUG_ERROR("Failed dm_mo_update_framework_property_wraper() : %d", err_code);
819                 }
820         }
821
822         /*
823          * Update Runtime property tbl
824          */
825         if (mo_node->runtime_property != NULL) {
826                 err_code = dm_mo_update_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
827                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
828                         _DEBUG_ERROR("Failed dm_mo_update_runtime_property_wraper() : %d", err_code);
829                 }
830         }
831
832         _EXTERN_FUNC_EXIT;
833
834         return err_code;
835 }
836
837 sync_agent_dm_mo_error_e dm_get_child_mo_list(sync_agent_dm_mo_type_e type, const char *mo_path, sync_agent_dm_mo_node_s ** mo_node_list, int *count, sync_agent_dm_mo_get_option_e option)
838 {
839         _EXTERN_FUNC_ENTER;
840
841         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
842
843         _DEBUG_INFO("mo_path : %s", mo_path);
844
845         sync_agent_dm_mo_error_e err_code = dm_mo_get_child_node_wraper(type, mo_path, mo_node_list, count);
846         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
847                 _DEBUG_ERROR("Failed to dm_mo_get_child_node_wraper : [%d]", err_code);
848                 _EXTERN_FUNC_EXIT;
849                 return err_code;
850         }
851
852         if (option == SYNC_AGENT_DM_MO_GET_OPTION_NODE) {
853                 _EXTERN_FUNC_EXIT;
854                 return SYNC_AGENT_DM_MO_SUCCESS;
855         }
856
857         /*
858          * todo Set Property to node list
859          */
860         int i = 0;
861         for (; i < *count; i++) {
862                 err_code = dm_mo_get_framework_property_wraper((*mo_node_list)[i].id, &((*mo_node_list)[i].framework_property));
863                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
864                         _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
865                 }
866                 err_code = dm_mo_get_runtime_property_wraper((*mo_node_list)[i].id, &((*mo_node_list)[i].runtime_property));
867                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
868                         _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
869                 }
870         }
871
872         _EXTERN_FUNC_EXIT;
873
874         return SYNC_AGENT_DM_MO_SUCCESS;
875 }
876
877 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_descendant_mo_tree(sync_agent_dm_mo_type_e type, const char *mo_path, sync_agent_dm_mo_node_s ** root_node, int *count, sync_agent_dm_mo_get_option_e option)
878 {
879         _EXTERN_FUNC_ENTER;
880
881         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
882
883         sync_agent_dm_mo_error_e err_code = dm_get_mo(mo_path, root_node, option);
884         _DEBUG_INFO("mo_path : %s", mo_path);
885         if(err_code == SYNC_AGENT_DM_MO_FAIL) {
886                 return err_code;
887         }
888         /*
889          * Recursive Call
890          */
891         err_code = _recursive_get_Descendant_MO_List(type, mo_path, *root_node, count, option);
892         _DEBUG_INFO("get_decendant mo list : %d", err_code);
893         /* __print_Tree(*root_node); */
894
895         _EXTERN_FUNC_EXIT;
896
897         return err_code;
898 }
899
900 sync_agent_dm_mo_error_e dm_get_mo(const char *mo_path, sync_agent_dm_mo_node_s ** mo_node, sync_agent_dm_mo_get_option_e option)
901 {
902         _EXTERN_FUNC_ENTER;
903
904         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
905
906         _DEBUG_INFO("mo_path : %s", mo_path);
907
908         sync_agent_dm_mo_error_e err_code = dm_mo_get_node_wraper(mo_path, mo_node);
909         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
910                 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
911                 if( err_code == SYNC_AGENT_DM_MO_FAIL) {
912                         if( *mo_node != NULL ) {
913                                 sync_agent_free_mo_item(*mo_node);
914                         }
915                 }
916                 return err_code;
917         }
918
919         if (*mo_node == NULL) {
920                 return SYNC_AGENT_DM_MO_FAIL;
921         }
922
923         if (option == SYNC_AGENT_DM_MO_GET_OPTION_ALL) {
924                 err_code = dm_mo_get_framework_property_wraper((*mo_node)->id, &((*mo_node)->framework_property));
925                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
926                         _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
927                         goto error;
928                 } else {
929                         _DEBUG_INFO("dm_mo_get_framework_property_wraper success");
930                 }
931                 err_code = dm_mo_get_runtime_property_wraper((*mo_node)->id, &((*mo_node)->runtime_property));
932                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
933                         _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
934                         goto error;
935                 } else {
936                         _DEBUG_INFO("dm_mo_get_runtime_property_wraper success");
937                 }
938         }
939
940         _EXTERN_FUNC_EXIT;
941
942         return err_code;
943  error:
944         return err_code;
945 }
946
947 sync_agent_dm_mo_error_e dm_get_mos(const char *mo_path, sync_agent_dm_mo_node_s ** mo_node, sync_agent_dm_mo_get_option_e option)
948 {
949         _EXTERN_FUNC_ENTER;
950
951         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
952
953         _DEBUG_INFO("mo_path : %s", mo_path);
954
955         sync_agent_dm_mo_error_e err_code = dm_mo_get_nodes_wraper(mo_path, mo_node);
956         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
957                 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
958                 return err_code;
959         }
960
961         if (*mo_node == NULL) {
962                 return SYNC_AGENT_DM_MO_FAIL;
963         }
964
965         if (option == SYNC_AGENT_DM_MO_GET_OPTION_ALL) {
966
967                 sync_agent_dm_mo_node_s *iter = NULL;
968                 int i = 0;
969                 iter = *mo_node;
970
971                 for (iter = *mo_node; iter != NULL; iter = iter->next_node, i++) {
972                         _DEBUG_INFO("mo_node id : %d", iter->id);
973                         err_code = dm_mo_get_framework_property_wraper(iter->id, &(iter->framework_property));
974                         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
975                                 _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
976                                 goto error;
977                         } else {
978                                 _DEBUG_INFO("dm_mo_get_framework_property_wraper success");
979                         }
980                         err_code = dm_mo_get_runtime_property_wraper(iter->id, &(iter->runtime_property));
981                         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
982                                 _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
983                                 goto error;
984                         } else {
985                                 _DEBUG_INFO("dm_mo_get_runtime_property_wraper success");
986                         }
987                 }
988         }
989
990         _EXTERN_FUNC_EXIT;
991
992         return err_code;
993  error:
994         return err_code;
995 }
996
997 EXPORT_API sync_agent_dm_mo_error_e sync_agent_is_exist_mo(const char *mo_path, int *is_exist)
998 {
999         _EXTERN_FUNC_ENTER;
1000
1001         retvm_if(mo_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_path is NULL !!");
1002
1003         _DEBUG_INFO("mo_path : %s", mo_path);
1004
1005         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1006         err_code = dm_mo_is_exist_node_wraper(mo_path);
1007         _DEBUG_INFO("is exist node : %d", err_code);
1008         if (err_code == SYNC_AGENT_DM_MO_EXIST_NODE) {
1009                 *is_exist = 1;
1010         } else if (err_code == SYNC_AGENT_DM_MO_NOT_EXIST_NODE) {
1011                 *is_exist = 0;
1012         } else {
1013                 _DEBUG_ERROR("dm_mo_is_exist_node_wraper() FAIL !!!");
1014                 *is_exist = 0;
1015                 _EXTERN_FUNC_EXIT;
1016                 return SYNC_AGENT_DM_MO_FAIL;
1017         }
1018
1019         _EXTERN_FUNC_EXIT;
1020
1021         return SYNC_AGENT_DM_MO_SUCCESS;
1022 }
1023
1024 void dm_free_mo(sync_agent_dm_mo_node_s * mo_node, int count)
1025 {
1026         _EXTERN_FUNC_ENTER;
1027
1028         _DEBUG_INFO("free mo node start");
1029         if ((mo_node) != NULL && count > 0) {
1030                 int i = 0;
1031                 for (i = 0; i < count; ++i) {
1032
1033                         if ((mo_node[i]).name != NULL) {
1034                                 free((mo_node[i]).name);
1035                         }
1036                         if ((mo_node[i]).value != NULL) {
1037                                 free((mo_node[i]).value);
1038                         }
1039                         if ((mo_node[i]).full_path != NULL) {
1040                                 free((mo_node[i]).full_path);
1041                         }
1042                         if ((mo_node[i]).runtime_property != NULL) {
1043                                 if ((mo_node[i]).runtime_property->acl != NULL) {
1044                                         free((mo_node[i]).runtime_property->acl);
1045                                 }
1046                                 if ((mo_node[i]).runtime_property->name != NULL) {
1047                                         free((mo_node[i]).runtime_property->name);
1048                                 }
1049                                 if ((mo_node[i]).runtime_property->size != NULL) {
1050                                         free((mo_node[i]).runtime_property->size);
1051                                 }
1052                                 if ((mo_node[i]).runtime_property->title != NULL) {
1053                                         free((mo_node[i]).runtime_property->title);
1054                                 }
1055                                 if ((mo_node[i]).runtime_property->tStamp != NULL) {
1056                                         free((mo_node[i]).runtime_property->tStamp);
1057                                 }
1058                                 if ((mo_node[i]).runtime_property->type_value != NULL) {
1059                                         free((mo_node[i]).runtime_property->type_value);
1060                                 }
1061                                 if ((mo_node[i]).runtime_property->verNo != NULL) {
1062                                         free((mo_node[i]).runtime_property->verNo);
1063                                 }
1064                         }
1065                         if ((mo_node[i]).framework_property != NULL) {
1066                                 if ((mo_node[i]).framework_property->defaultValue != NULL) {
1067                                         free((mo_node[i]).framework_property->defaultValue);
1068                                 }
1069                                 if ((mo_node[i]).framework_property->description != NULL) {
1070                                         free((mo_node[i]).framework_property->description);
1071                                 }
1072                                 if ((mo_node[i]).framework_property->dfTitle != NULL) {
1073                                         free((mo_node[i]).framework_property->dfTitle);
1074                                 }
1075                                 if ((mo_node[i]).framework_property->dfType_Value != NULL) {
1076                                         free((mo_node[i]).framework_property->dfType_Value);
1077                                 }
1078                         }
1079                         if ((mo_node[i]).child_node_list != NULL) {
1080                                 dm_free_mo((mo_node[i]).child_node_list, (mo_node[i]).child_node_cnt);
1081                         }
1082                         if ((mo_node[i]).next_node != NULL) {
1083                                 dm_free_mo((mo_node[i]).next_node, 1);
1084                         }
1085                 }
1086
1087                 free(mo_node);
1088         }
1089         _EXTERN_FUNC_EXIT;
1090 }
1091
1092 EXPORT_API int sync_agent_traverse_mo_tree_preorder(sync_agent_dm_mo_node_s * root_ptr, sync_agent_mo_worker_cb func_ptr, int depth, int err_stop, void **arg)
1093 {
1094         _EXTERN_FUNC_ENTER;
1095
1096         retvm_if(root_ptr == NULL, -1, "root_ptr is NULL !!");
1097
1098         _DEBUG_INFO("[%d] mo_node name : %s", depth, root_ptr->name);
1099
1100         int ret = 0;
1101
1102         if (depth != 0) {
1103                 ret = func_ptr(root_ptr, depth, arg);
1104                 if (ret != -1 && err_stop != 0) {
1105                         return ret;
1106                 }
1107         }
1108
1109         int i = 0;
1110         for (; i < root_ptr->child_node_cnt; i++) {
1111                 ret = sync_agent_traverse_mo_tree_preorder(&(root_ptr->child_node_list[i]), func_ptr, depth + 1, err_stop, arg);
1112                 if (ret != -1 && err_stop != 0) {
1113                         return ret;
1114                 }
1115         }
1116
1117         _EXTERN_FUNC_EXIT;
1118
1119         return ret;
1120 }
1121
1122 /******************************************* TNDS ******************************************/
1123
1124 EXPORT_API sync_agent_dm_mo_error_e sync_agent_export_tnds_stream(sync_agent_dm_tnds_type_e tnds_type, sync_agent_dm_mo_type_e mo_type, const char *mo_full_path, char **output_stream, unsigned int *byte_size)
1125 {
1126         _EXTERN_FUNC_ENTER;
1127
1128         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1129
1130         sync_agent_dm_mo_node_s *root_node = NULL;
1131         int node_count = 0;
1132         sync_agent_dm_mo_error_e err;
1133
1134         err = sync_agent_get_descendant_mo_tree(mo_type, mo_full_path, &root_node, &node_count, SYNC_AGENT_DM_MO_GET_OPTION_ALL);
1135         _DEBUG_INFO("get decendant mo list : %d", err);
1136
1137         sync_agent_dm_mo_error_e mo_error = dm_get_tnds_from_db(tnds_type, root_node, output_stream, byte_size);
1138         _DEBUG_INFO("get tnds mo list : %d", mo_error);
1139         dm_free_mo(root_node, 1);
1140
1141         _EXTERN_FUNC_EXIT;
1142
1143         return mo_error;
1144 }
1145
1146 EXPORT_API sync_agent_dm_mo_error_e sync_agent_import_tnds_stream(sync_agent_dm_tnds_action_e tnds_action, sync_agent_dm_tnds_type_e tnds_type, sync_agent_dm_mo_type_e mo_type, const char *mo_full_path, char *input_stream, unsigned int byte_size)
1147 {
1148         _EXTERN_FUNC_ENTER;
1149
1150         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1151
1152         _EXTERN_FUNC_EXIT;
1153
1154         return dm_insert_tnds_to_db(tnds_action, tnds_type, mo_type, mo_full_path, input_stream, byte_size);
1155 }
1156
1157 EXPORT_API sync_agent_dm_mo_error_e sync_agent_delete_all_mo_table()
1158 {
1159         _EXTERN_FUNC_ENTER;
1160
1161         sync_agent_dm_mo_error_e err_code = sync_agent_begin_transaction_mo();
1162
1163         err_code = dm_mo_delete_all_node_wraper();
1164         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1165                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1166                 return err_code;
1167         }
1168
1169         err_code = dm_mo_delete_all_framework_property_wraper();
1170         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1171                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1172                 return err_code;
1173         }
1174
1175         err_code = dm_mo_delete_all_runtime_property_wraper();
1176         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1177                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1178         } else {
1179                 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1180         }
1181
1182         _EXTERN_FUNC_EXIT;
1183
1184         return err_code;
1185 }
1186
1187 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_mo_type(const char *mo_full_path, sync_agent_dm_mo_type_e * mo_type)
1188 {
1189         _EXTERN_FUNC_ENTER;
1190
1191         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1192
1193         *mo_type = dm_mo_get_mo_type_wraper(mo_full_path);
1194
1195         _EXTERN_FUNC_EXIT;
1196
1197         return SYNC_AGENT_DM_MO_SUCCESS;
1198 }
1199
1200 sync_agent_dm_mo_error_e dm_get_acl_value(const char *mo_full_path, sync_agent_dm_mo_node_s ** mo_node)
1201 {
1202         _EXTERN_FUNC_ENTER;
1203
1204         retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1205
1206         sync_agent_dm_mo_node_s *iter = NULL;
1207         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1208
1209         if (!strcmp(mo_full_path, ".")) {
1210                 err_code = dm_mo_get_node_wraper(mo_full_path, mo_node);
1211         } else {
1212                 /* get nodes */
1213                 err_code = dm_mo_get_nodes_wraper(mo_full_path, mo_node);
1214
1215         }
1216         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1217                 _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code);
1218                 return SYNC_AGENT_DM_MO_FAIL;
1219         }
1220         retvm_if(*mo_node == NULL, SYNC_AGENT_DM_MO_NOT_EXIST_NODE, "mo_node is NULL !!");
1221
1222         int i = 0;
1223         for (iter = (*mo_node); iter != NULL; iter = iter->next_node) {
1224                 _DEBUG_INFO("iter mo count : %d", i++);
1225
1226                 err_code = dm_mo_get_runtime_property_wraper(iter->id, &(iter->runtime_property));
1227                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1228                         _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
1229                         return SYNC_AGENT_DM_MO_FAIL;
1230                 }
1231
1232                 err_code = dm_mo_get_framework_property_wraper(iter->id, &(iter->framework_property));
1233                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1234                         _DEBUG_ERROR("Failed to dm_mo_get_framework_property_wraper : [%d]", err_code);
1235                         return SYNC_AGENT_DM_MO_FAIL;
1236                 }
1237
1238                 if (iter->runtime_property != NULL && iter->runtime_property->acl != NULL) {
1239                         _DEBUG_INFO("mo node id : %d", iter->id);
1240                         _DEBUG_INFO("mo node acl : %s", iter->runtime_property->acl);
1241                         _DEBUG_INFO("current node_acl");
1242                         continue;
1243                 } else {
1244                         sync_agent_dm_mo_node_s *mo_parent_node = NULL;
1245
1246                         err_code = dm_mo_get_node_from_id_wraper(iter->parent_id, &mo_parent_node);
1247                         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1248                                 _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err_code);
1249                                 if(mo_parent_node != NULL) {
1250                                         free(mo_parent_node);
1251                                 }
1252                                 return SYNC_AGENT_DM_MO_FAIL;
1253                         }
1254                         int parent_id = -1;
1255
1256                         while (mo_parent_node != NULL) {
1257
1258                                 err_code = dm_mo_get_runtime_property_wraper(mo_parent_node->id, &(mo_parent_node->runtime_property));
1259                                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1260                                         _DEBUG_ERROR("Failed to dm_mo_get_runtime_property_wraper : [%d]", err_code);
1261                                 }
1262
1263                                 if (mo_parent_node->runtime_property != NULL && mo_parent_node->runtime_property->acl != NULL) {
1264                                         _DEBUG_INFO("current node_acl");
1265
1266                                         iter->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
1267                                         if (iter->runtime_property == NULL) {
1268                                                 _DEBUG_ERROR("alloc fail");
1269
1270                                                 dm_free_mo(mo_parent_node, 1);
1271                                                 mo_parent_node = NULL;
1272
1273                                                 return SYNC_AGENT_DM_MO_FAIL;
1274                                         }
1275
1276                                         iter->runtime_property->acl = strdup(mo_parent_node->runtime_property->acl);
1277                                         dm_free_mo(mo_parent_node, 1);
1278                                         mo_parent_node = NULL;
1279                                         break;
1280                                 } else {
1281                                         _DEBUG_INFO("parent node_acl null");
1282                                 }
1283
1284                                 parent_id = mo_parent_node->parent_id;
1285
1286                                 dm_free_mo(mo_parent_node, 1);
1287                                 mo_parent_node = NULL;
1288                                 if (parent_id == -1) {
1289                                         _DEBUG_INFO("root node get acl");
1290                                         break;
1291                                 }
1292
1293                                 err_code = dm_mo_get_node_from_id_wraper(parent_id, &mo_parent_node);
1294                                 if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1295                                         _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err_code);
1296
1297                                         dm_free_mo(mo_parent_node, 1);
1298                                         mo_parent_node = NULL;
1299
1300                                         return SYNC_AGENT_DM_MO_FAIL;
1301                                 }
1302                         }
1303                 }
1304         }
1305         _EXTERN_FUNC_EXIT;
1306         return SYNC_AGENT_DM_MO_SUCCESS;
1307 }
1308
1309 /*
1310  * check_acl = 0 : not permission acl
1311  * check_acl = 1 : not have accesstype
1312  * check_acl = 2 : permission acl
1313  */
1314 EXPORT_API sync_agent_dm_mo_error_e sync_agent_check_acl_value(const char *mo_full_path, sync_agent_dm_mo_access_type_e access_type, const char *server_id, int *check_acl)
1315 {
1316         _EXTERN_FUNC_ENTER;
1317
1318         if (mo_full_path == NULL || server_id == NULL || access_type == SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) {
1319                 _DEBUG_INFO("mo_full_path == NULL || acl_value == NULL || access_type == SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET\n");
1320                 _EXTERN_FUNC_EXIT;
1321                 return SYNC_AGENT_DM_MO_FAIL;
1322         }
1323
1324         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1325         sync_agent_dm_mo_node_s *mo_node = NULL;
1326         sync_agent_dm_mo_node_s *iter = NULL;
1327         char *mo_acl_value = NULL;
1328         int isSearch_value = 0;
1329         int isExist_all = 0;
1330         int server_id_length = 0;
1331         char *ptr_sev_id = NULL;
1332
1333         /* get acl value */
1334         err_code = dm_get_acl_value(mo_full_path, &mo_node);
1335         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1336                 *check_acl = 0;
1337                 goto return_part;
1338         }
1339
1340         if (mo_node == NULL) {
1341                 _DEBUG_INFO("command_str is NULL");
1342                 *check_acl = 0;
1343                 err_code = SYNC_AGENT_DM_MO_FAIL;
1344                 goto return_part;
1345         }
1346
1347         /*check accecctype error */
1348         _DEBUG_INFO("check accesstype : %d", access_type);
1349
1350         if (mo_node->framework_property != NULL) {
1351                 _DEBUG_INFO("framework accesstype : %d", mo_node->framework_property->accessType);
1352
1353                 if ((mo_node->framework_property->accessType != SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) && (mo_node->framework_property->accessType & access_type) != access_type) {
1354
1355                         *check_acl = 1;
1356                         goto return_part;
1357                 }
1358         }
1359
1360         for (iter = mo_node; iter != NULL; iter = iter->next_node) {
1361                 _DEBUG_INFO("check mo node acl iter\n");
1362                 if (iter->runtime_property == NULL || iter->runtime_property->acl == NULL) {
1363                         _DEBUG_INFO("mo_acl_value is NULL\n");
1364                         *check_acl = 2;
1365                         err_code = SYNC_AGENT_DM_MO_SUCCESS;
1366                         goto return_part;
1367                 }
1368
1369                 mo_acl_value = iter->runtime_property->acl;
1370
1371                 _DEBUG_INFO("ALC : %s\n", mo_acl_value);
1372
1373                 if (isSearch_value == 2) {
1374                         isSearch_value = 1;
1375                         _DEBUG_INFO("acl ok \n");
1376                 } else {
1377                         _DEBUG_INFO("mo_acl_value = %s\n", mo_acl_value);
1378                         _DEBUG_INFO("access_type = %d\n", access_type);
1379
1380                         char *command_str = NULL;
1381                         command_str = _get_access_type_string(access_type);
1382                         if (command_str == NULL) {
1383                                 _DEBUG_INFO("command_str is NULL");
1384                                 *check_acl = 0;
1385                                 err_code = SYNC_AGENT_DM_MO_FAIL;
1386                                 goto return_part;
1387                         }
1388
1389                         /* search acl command and server_id */
1390                         char *ptr_cmd = strstr(mo_acl_value, command_str);
1391                         while (ptr_cmd != NULL) {
1392                                 char *mo_server_id = NULL;
1393
1394                                 _DEBUG_INFO("########## Operation Start ###########");
1395                                 _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd);
1396                                 ptr_cmd += strlen(command_str);
1397
1398                                 _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd);
1399                                 ptr_sev_id = strstr(ptr_cmd, "&");
1400
1401                                 if (ptr_sev_id != NULL) {
1402                                         server_id_length = strlen(ptr_cmd) - strlen(ptr_sev_id - 1) + 1;
1403                                         _DEBUG_INFO("ptr_sev_id = %s\n", ptr_sev_id);
1404                                 } else {
1405                                         _DEBUG_INFO("ptr_sev_id = %s\n", ptr_cmd);
1406                                         server_id_length = strlen(ptr_cmd);
1407                                 }
1408
1409                                 _DEBUG_INFO("server_id_length = %d\n", server_id_length);
1410                                 mo_server_id = (char *)calloc(server_id_length + 1, sizeof(char));
1411                                 if (mo_server_id == NULL) {
1412                                         _DEBUG_ERROR("CALLOC failed !!!");
1413                                         *check_acl = 0;
1414                                         err_code = SYNC_AGENT_DM_MO_FAIL;
1415                                         goto return_part;
1416                                 }
1417                                 memset(mo_server_id, 0, sizeof(char)*(server_id_length + 1));
1418                                 strncpy(mo_server_id, ptr_cmd, server_id_length);
1419                                 _DEBUG_INFO("[ mo_server_id = %s ]\n", mo_server_id);
1420
1421                                 if (strcmp(mo_server_id, server_id) == 0) {
1422                                         _DEBUG_INFO("====> Search ACL Server_id");
1423                                         isSearch_value = 2;
1424
1425                                         if (mo_server_id != NULL) {
1426                                                 free(mo_server_id);
1427                                                 mo_server_id = NULL;
1428                                         }
1429
1430                                         break;
1431                                 } else if (strcmp(mo_server_id, "*") == 0) {
1432                                         _DEBUG_INFO("Exist All Format");
1433                                         isExist_all = 1;
1434                                 }
1435
1436                                 /* prepare next value check */
1437                                 if (ptr_sev_id != NULL) {
1438                                         ptr_cmd = strstr(ptr_sev_id, command_str);
1439                                 } else {
1440                                         ptr_cmd = NULL;
1441                                 }
1442
1443                                 if (mo_server_id != NULL) {
1444                                         free(mo_server_id);
1445                                         mo_server_id = NULL;
1446                                 }
1447                         }
1448                 }
1449         }
1450
1451
1452         if (mo_node != NULL)
1453                 dm_free_mo(mo_node, 1);
1454
1455         if (isSearch_value == 0) {
1456
1457                 if (isExist_all == 1) {
1458                         _DEBUG_INFO("##############################>>>>>> Search Value => exist * format !!");
1459                         *check_acl = 2;
1460
1461                         _EXTERN_FUNC_EXIT;
1462
1463                         return err_code;
1464                 } else {
1465                         _DEBUG_INFO("##############################>>>>>> Not Search Value ");
1466                         *check_acl = 0;
1467
1468                         _EXTERN_FUNC_EXIT;
1469
1470                         return err_code;
1471                 }
1472
1473         } else {
1474                 _DEBUG_INFO("##############################>>>>>> Search Value !!");
1475                 *check_acl = 2;
1476
1477                 _EXTERN_FUNC_EXIT;
1478
1479                 return err_code;
1480         }
1481
1482  return_part:
1483
1484         if (mo_node != NULL) {
1485                 dm_free_mo(mo_node, 1);
1486         }
1487
1488         _EXTERN_FUNC_EXIT;
1489         return err_code;
1490 }
1491
1492 EXPORT_API sync_agent_dm_mo_error_e sync_agent_create_mo_acc_item(sync_agent_dm_acc_info_s ** acc_info)
1493 {
1494         _EXTERN_FUNC_ENTER;
1495
1496         *acc_info = (sync_agent_dm_acc_info_s *) calloc(1, sizeof(sync_agent_dm_acc_info_s));
1497         if (*acc_info == NULL) {
1498                 return SYNC_AGENT_DM_MO_FAIL;
1499         }
1500
1501         _EXTERN_FUNC_EXIT;
1502
1503         return SYNC_AGENT_DM_MO_SUCCESS;
1504 }
1505
1506 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_mo_acc_item(sync_agent_dm_mo_acc_item_info_s * sync_agent_mo_acc_info_item, sync_agent_dm_acc_info_s ** acc_info)
1507 {
1508         _EXTERN_FUNC_ENTER;
1509
1510         sync_agent_dm_mo_error_e mo_error = SYNC_AGENT_DM_MO_SUCCESS;
1511
1512         const char *server_id_string = "ServerID";
1513         const char *acc_type_string = 0;
1514
1515         if (sync_agent_mo_acc_info_item == NULL) {
1516                 return SYNC_AGENT_DM_MO_FAIL;
1517         }
1518
1519         _DEBUG_INFO("get acc info : %d ", sync_agent_mo_acc_info_item->acc_type);
1520         _DEBUG_INFO("get acc info : %s ", sync_agent_mo_acc_info_item->serverid);
1521
1522         switch (sync_agent_mo_acc_info_item->acc_type) {
1523         case DEVICE_MANAGE_ACC_TYPE_SERVER:
1524                 acc_type_string = "/ServerAppAuth/";
1525                 break;
1526         case DEVICE_MANAGE_ACC_TYPE_CLIENT:
1527                 acc_type_string = "/ClientAppAuth/";
1528                 break;
1529         }
1530
1531         /*sync_agent_dm_acc_info_s *acc_info = NULL; */
1532         mo_error = dm_mo_get_acc_info_wraper(sync_agent_mo_acc_info_item->serverid, server_id_string, acc_type_string, acc_info);
1533
1534         if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
1535                 _DEBUG_ERROR("Failed to dm_mo_get_acc_info_wraper()");
1536                 return mo_error;
1537         }
1538
1539         if (*acc_info != NULL) {
1540                 _DEBUG_INFO("auth_name : %s", (*acc_info)->auth_name);
1541                 _DEBUG_INFO("auth_secret : %s", (*acc_info)->auth_secret);
1542                 _DEBUG_INFO("auth_data : %s", (*acc_info)->auth_data);
1543                 _DEBUG_INFO("auth_type : %s", (*acc_info)->auth_type);
1544                 _DEBUG_INFO("auth_level : %s", (*acc_info)->auth_level);
1545                 _DEBUG_INFO("addr : %s\n", (*acc_info)->addr);
1546         } else {
1547                 _DEBUG_INFO("\nacc_info is NULL!!\n");
1548                 return SYNC_AGENT_DM_MO_FAIL;
1549         }
1550
1551         _EXTERN_FUNC_EXIT;
1552
1553         return mo_error;
1554 }
1555
1556 EXPORT_API sync_agent_dm_mo_error_e sync_agent_update_mo_acc_item(sync_agent_dm_mo_acc_item_info_s * sync_agent_mo_acc_info_item, sync_agent_dm_acc_info_s * acc_info)
1557 {
1558         _EXTERN_FUNC_ENTER;
1559
1560         sync_agent_dm_mo_error_e mo_error = SYNC_AGENT_DM_MO_SUCCESS;
1561         const char *server_id_string = "ServerID";
1562         const char *acc_type_string = NULL;
1563
1564         if (sync_agent_mo_acc_info_item == NULL) {
1565                 _EXTERN_FUNC_EXIT;
1566                 return SYNC_AGENT_DM_MO_FAIL;
1567         }
1568
1569         switch (sync_agent_mo_acc_info_item->acc_type) {
1570         case DEVICE_MANAGE_ACC_TYPE_SERVER:
1571                 acc_type_string = "/ServerAppAuth/";
1572                 break;
1573         case DEVICE_MANAGE_ACC_TYPE_CLIENT:
1574                 acc_type_string = "/ClientAppAuth/";
1575                 break;
1576         }
1577
1578         mo_error = dm_mo_set_acc_info_wraper(sync_agent_mo_acc_info_item->serverid, server_id_string, acc_type_string, acc_info);
1579
1580         if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
1581                 _DEBUG_ERROR("Failed to dm_mo_get_acc_info_wraper()");
1582                 return mo_error;
1583         }
1584
1585         if (acc_info != NULL) {
1586                 _DEBUG_INFO("\nauth_name : %s", acc_info->auth_name);
1587                 _DEBUG_INFO("auth_secret : %s", acc_info->auth_secret);
1588                 _DEBUG_INFO("auth_data : %s", acc_info->auth_data);
1589                 _DEBUG_INFO("auth_type : %s", acc_info->auth_type);
1590                 _DEBUG_INFO("auth_level : %s", acc_info->auth_level);
1591                 _DEBUG_INFO("addr : %s", acc_info->addr);
1592         } else {
1593                 _DEBUG_INFO("\nacc_info is NULL!!\n");
1594         }
1595
1596         _EXTERN_FUNC_EXIT;
1597
1598         return mo_error;
1599 }
1600
1601 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_mo_acc_item(sync_agent_dm_acc_info_s ** acc_info)
1602 {
1603         _EXTERN_FUNC_ENTER;
1604
1605         if ((*acc_info) != NULL) {
1606                 if ((*acc_info)->addr != NULL) {
1607                         free((*acc_info)->addr);
1608                         (*acc_info)->addr = NULL;
1609                 }
1610                 if ((*acc_info)->auth_data != NULL) {
1611                         free((*acc_info)->auth_data);
1612                         (*acc_info)->auth_data = NULL;
1613                 }
1614                 if ((*acc_info)->auth_level != NULL) {
1615                         free((*acc_info)->auth_level);
1616                         (*acc_info)->auth_level = NULL;
1617                 }
1618                 if ((*acc_info)->auth_name != NULL) {
1619                         free((*acc_info)->auth_name);
1620                         (*acc_info)->auth_name = NULL;
1621                 }
1622                 if ((*acc_info)->auth_secret != NULL) {
1623                         free((*acc_info)->auth_secret);
1624                         (*acc_info)->auth_secret = NULL;
1625                 }
1626                 if ((*acc_info)->auth_type != NULL) {
1627                         free((*acc_info)->auth_type);
1628                         (*acc_info)->auth_type = NULL;
1629                 }
1630                 (*acc_info) = NULL;
1631         }
1632
1633         _EXTERN_FUNC_EXIT;
1634
1635         return SYNC_AGENT_DM_MO_SUCCESS;
1636 }
1637
1638 EXPORT_API sync_agent_dm_mo_error_e sync_agent_uptodate_mo_table(sync_agent_dm_mo_type_e mo_type, int mo_plugin_id, char *mo_root)
1639 {
1640         _EXTERN_FUNC_ENTER;
1641
1642         retvm_if(mo_root == NULL, SYNC_AGENT_DM_MO_FAIL, "uptodate mo root NULL !!");
1643
1644         _DEBUG_INFO("mo_type : %d", mo_type);
1645
1646         sync_agent_dm_mo_node_s *root_node = NULL;
1647         int count = 0;
1648         sync_agent_dm_mo_error_e err;
1649         err = sync_agent_get_descendant_mo_tree(mo_type, mo_root, &root_node, &count, SYNC_AGENT_DM_MO_GET_OPTION_NODE);
1650         _DEBUG_INFO("get decendant mo list : %d", err);
1651
1652         plugin_get_mo_value_cb func_point_get_value = NULL;
1653         _DEBUG_INFO("PLUGIN ID : %d", mo_plugin_id);
1654         func_point_get_value = plugin_get_function_get_mo_value(mo_plugin_id);
1655
1656         sync_agent_traverse_mo_tree_preorder(root_node, _update_MO_info, 0, 0, (void **)(&func_point_get_value));
1657
1658         _EXTERN_FUNC_EXIT;
1659
1660         return SYNC_AGENT_DM_MO_SUCCESS;
1661 }
1662
1663 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_serverinfo(sync_agent_dm_server_info_s ** server_info)
1664 {
1665         _EXTERN_FUNC_ENTER;
1666
1667         sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
1668         const char *server_id_string = "ServerID";
1669
1670         err = dm_mo_get_server_id_list_wraper(server_id_string, server_info);
1671         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
1672                 _DEBUG_INFO("get server id list : %d", err);
1673                 return err;
1674         }
1675
1676         _DEBUG_INFO("get server id list result : %d", err);
1677         _EXTERN_FUNC_EXIT;
1678         return err;
1679 }
1680
1681 EXPORT_API sync_agent_dm_mo_error_e sync_agent_free_serverinfo(sync_agent_dm_server_info_s * server_info)
1682 {
1683         _EXTERN_FUNC_ENTER;
1684
1685         if (server_info != NULL) {
1686                 if (server_info->server_id != NULL) {
1687                         free(server_info->server_id);
1688                         server_info->server_id = NULL;
1689                 }
1690                 if (server_info->next != NULL) {
1691                         sync_agent_free_serverinfo(server_info->next);
1692                         server_info->next = NULL;
1693                 }
1694
1695                 free(server_info);
1696         }
1697
1698         _EXTERN_FUNC_EXIT;
1699
1700         return SYNC_AGENT_DM_MO_SUCCESS;
1701 }
1702
1703 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_serverid(sync_agent_dm_mo_type_e mo_type, char **server_id)
1704 {
1705         _EXTERN_FUNC_ENTER;
1706
1707         _DEBUG_INFO("mo_type : %d", mo_type);
1708
1709         const char *server_id_string = "ServerID";
1710
1711         sync_agent_dm_server_info_s *head_ptr = NULL;
1712         dm_mo_get_server_id_list_wraper(server_id_string, &head_ptr);
1713
1714         sync_agent_dm_server_info_s *cursor_ptr = head_ptr;
1715
1716         while (cursor_ptr != NULL) {
1717                 _DEBUG_INFO("server_id : %s", cursor_ptr->server_id);
1718                 _DEBUG_INFO("server_type : %d", cursor_ptr->server_type);
1719
1720                 int result = mo_type & (cursor_ptr->server_type);
1721
1722                 if (result == mo_type) {
1723                         _DEBUG_INFO("corrected");
1724                         *server_id = g_strdup(cursor_ptr->server_id);
1725                         sync_agent_free_serverinfo(head_ptr);
1726                         return SYNC_AGENT_DM_MO_SUCCESS;
1727                 }
1728
1729                 cursor_ptr = cursor_ptr->next;
1730         }
1731
1732         sync_agent_free_serverinfo(head_ptr);
1733         _EXTERN_FUNC_EXIT;
1734
1735         return SYNC_AGENT_DM_MO_FAIL;
1736 }
1737
1738 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_root_path(const char *mo_full_path, char **root_path)
1739 {
1740         _EXTERN_FUNC_ENTER;
1741
1742         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1743         err_code = dm_mo_get_root_path_wraper(mo_full_path, root_path);
1744         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1745                 _DEBUG_ERROR("Failed dm_mo_get_root_path_wraper() : [%d]", err_code);
1746                 return SYNC_AGENT_DM_MO_FAIL;
1747         } else {
1748                 _DEBUG_INFO("Successed dm_mo_get_root_path_wraper() : [%s]", *root_path);
1749
1750         }
1751
1752         _EXTERN_FUNC_EXIT;
1753
1754         return SYNC_AGENT_DM_MO_SUCCESS;
1755 }
1756
1757 EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_server_type(const char *server_id, int *server_type)
1758 {
1759         _EXTERN_FUNC_ENTER;
1760
1761         retvm_if((server_id) == NULL, SYNC_AGENT_DM_MO_FAIL, "server_id is NULL!!");
1762
1763         _DEBUG_INFO("server_id : %s", server_id);
1764         const char *server_id_string = "ServerID";
1765
1766         sync_agent_dm_server_info_s *head_ptr = NULL;
1767         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1768         err_code = dm_mo_get_server_id_list_wraper(server_id_string, &head_ptr);
1769
1770         if (err_code != SYNC_AGENT_DM_MO_FAIL) {
1771                 sync_agent_dm_server_info_s *cursor_ptr = head_ptr;
1772                 while (cursor_ptr != NULL) {
1773                         if (cursor_ptr->server_id == NULL) {
1774                                 *server_type = 0;
1775                                 sync_agent_free_serverinfo(head_ptr);
1776                                 return SYNC_AGENT_DM_MO_SUCCESS;
1777                         }
1778                         _DEBUG_INFO("server_id : %s", cursor_ptr->server_id);
1779                         _DEBUG_INFO("server_type : %d", cursor_ptr->server_type);
1780
1781                         if (!strcmp(cursor_ptr->server_id, server_id)) {
1782                                 _DEBUG_INFO("corrected server_id : %s", server_id);
1783                                 *server_type = cursor_ptr->server_type;
1784                                 sync_agent_free_serverinfo(head_ptr);
1785                                 return SYNC_AGENT_DM_MO_SUCCESS;
1786                         }
1787                         cursor_ptr = cursor_ptr->next;
1788                 }
1789         } else {
1790
1791                 *server_type = 0;
1792                 sync_agent_free_serverinfo(head_ptr);
1793                 _EXTERN_FUNC_EXIT;
1794
1795                 return SYNC_AGENT_DM_MO_FAIL;
1796         }
1797
1798         *server_type = 0;
1799
1800         sync_agent_free_serverinfo(head_ptr);
1801         _EXTERN_FUNC_EXIT;
1802
1803         return SYNC_AGENT_DM_MO_SUCCESS;
1804 }
1805
1806 EXPORT_API sync_agent_dm_mo_error_e sync_agent_initialize_mo(int mo_plugin_id)
1807 {
1808         _EXTERN_FUNC_ENTER;
1809
1810         plugin_initialize func_point_initialize = NULL;
1811         func_point_initialize = plugin_get_function_initialize(mo_plugin_id);
1812
1813         if (func_point_initialize != NULL) {
1814                 int result = func_point_initialize();
1815                 if (result != 1) {
1816                         return SYNC_AGENT_DM_MO_FAIL;
1817                 }
1818         } else {
1819                 return SYNC_AGENT_DM_MO_FAIL;
1820         }
1821
1822         _EXTERN_FUNC_EXIT;
1823
1824         return SYNC_AGENT_DM_MO_SUCCESS;
1825 }
1826
1827 /******************************** static function implement **********************************/
1828
1829 int _update_MO_info(sync_agent_dm_mo_node_s * mo_node, int depth, void **arg)
1830 {
1831         _INNER_FUNC_ENTER;
1832
1833         if (mo_node == NULL) {
1834                 _DEBUG_TRACE("mo_node is NULL!!");
1835                 return -1;
1836         }
1837
1838         _DEBUG_TRACE("mo_node->full_path : %s", mo_node->full_path);
1839         _DEBUG_TRACE("mo_node->name : %s", mo_node->name);
1840         _DEBUG_TRACE("mo_node->value : %s", mo_node->value);
1841
1842         plugin_get_mo_value_cb func_point_get_value = (plugin_get_mo_value_cb) (*arg);
1843
1844         if (func_point_get_value != NULL) {
1845                 func_point_get_value(mo_node->full_path, mo_node->name, &(mo_node->value));
1846                 _DEBUG_TRACE("Be Called func_point_get_value();");
1847
1848                 dm_update_mo(mo_node->mo_type, mo_node);
1849         }
1850
1851         _INNER_FUNC_EXIT;
1852
1853         return 0;
1854 }
1855
1856 /******************************************************** Impl static function *************************************************************/
1857
1858 static int _get_parent_path(const char *mo_pull_path, char **mo_parent_path, char **mo_name)
1859 {
1860         _INNER_FUNC_ENTER;
1861
1862         int mo_pull_path_len = strlen(mo_pull_path);
1863
1864         char *last_delimit = strrchr(mo_pull_path, DELIMIT);
1865
1866         /*
1867          * Is Root Node
1868          */
1869         if (last_delimit == NULL) {
1870                 *mo_name = (char *)calloc(mo_pull_path_len + 1, sizeof(char));
1871                 if (*mo_name == NULL) {
1872                         _DEBUG_ERROR("CALLOC failed !!!");
1873                         return -1;
1874                 }
1875                 strncpy(*mo_name, mo_pull_path, mo_pull_path_len);
1876                 return 1;
1877         }
1878
1879         int name_len = strlen(last_delimit);
1880         int parent_path_len = mo_pull_path_len - name_len;
1881
1882         *mo_parent_path = (char *)calloc(parent_path_len + 1, sizeof(char));
1883         if (*mo_parent_path == NULL) {
1884                 _DEBUG_ERROR("CALLOC failed !!!");
1885                 return -1;
1886         }
1887         *mo_name = (char *)calloc(name_len, sizeof(char));
1888         if (*mo_name == NULL) {
1889                 _DEBUG_ERROR("CALLOC failed !!!");
1890                 return -1;
1891         }
1892
1893         strncpy(*mo_parent_path, mo_pull_path, parent_path_len);
1894         strncpy(*mo_name, last_delimit + 1, name_len);
1895
1896         _INNER_FUNC_EXIT;
1897
1898         return 0;
1899 }
1900
1901 static sync_agent_dm_mo_node_s *_create_default_mo_node(char *mo_full_path)
1902 {
1903         _INNER_FUNC_ENTER;
1904
1905         sync_agent_dm_mo_node_s *mo_node = (sync_agent_dm_mo_node_s *) calloc(1, sizeof(sync_agent_dm_mo_node_s));
1906         if (mo_node == NULL) {
1907                 _DEBUG_ERROR("CALLOC failed !!!");
1908                 return NULL;
1909         }
1910
1911         char *mo_parent_path = NULL;
1912         char *mo_name = NULL;
1913         int ret = _get_parent_path(mo_full_path, &mo_parent_path, &mo_name);
1914         if (ret == -1) {
1915                 dm_free_mo(mo_node, 1);
1916
1917                 if (mo_parent_path != NULL)
1918                         free(mo_parent_path);
1919
1920                 return NULL;
1921         }
1922
1923         _DEBUG_TRACE("mo_full_path : %s", mo_full_path);
1924         _DEBUG_TRACE("mo_parent_path : %s", mo_parent_path);
1925         _DEBUG_TRACE("mo_name : %s", mo_name);
1926
1927 /*      if (mo_parent_path != NULL) {
1928                 free(mo_parent_path);
1929         }*/
1930         mo_node->id = -1;
1931         mo_node->parent_id = -1;
1932         mo_node->name = mo_name;
1933         mo_node->full_path = mo_full_path;
1934         mo_node->value = NULL;
1935
1936         if (mo_parent_path == NULL) {
1937                 mo_node->type = SYNC_AGENT_DM_MO_NODE_ROOT;
1938                 _DEBUG_TRACE("------------------root node-----------------");
1939         } else {
1940                 mo_node->type = SYNC_AGENT_DM_MO_NODE_INTERIOR;
1941         }
1942         mo_node->framework_property = (sync_agent_dm_mo_framework_property_s *) calloc(1, sizeof(sync_agent_dm_mo_framework_property_s));
1943         if (mo_node->framework_property == NULL) {
1944                 _DEBUG_ERROR("CALLOC failed !!!");
1945                 dm_free_mo(mo_node, 1);
1946                 if (mo_parent_path != NULL)
1947                         free(mo_parent_path);
1948
1949                 return NULL;
1950         }
1951         mo_node->runtime_property = (sync_agent_dm_mo_runtime_property_s *) calloc(1, sizeof(sync_agent_dm_mo_runtime_property_s));
1952         if (mo_node->runtime_property == NULL) {
1953                 _DEBUG_ERROR("CALLOC failed !!!");
1954                 dm_free_mo(mo_node, 1);
1955                 if (mo_parent_path != NULL)
1956                         free(mo_parent_path);
1957
1958                 return NULL;
1959         }
1960
1961         if (mo_node->type == SYNC_AGENT_DM_MO_NODE_ROOT) {
1962                 mo_node->framework_property->dffFormat = SYNC_AGENT_DM_MO_FORMAT_NODE;
1963                 mo_node->framework_property->accessType = SYNC_AGENT_DM_MO_ACCESSTYPE_ADD | SYNC_AGENT_DM_MO_ACCESSTYPE_GET;
1964                 mo_node->runtime_property->acl = strdup("Get=*&Add=*");
1965                 mo_node->runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_NODE;
1966                 mo_node->runtime_property->name = strdup(".");
1967                 _DEBUG_TRACE("root node acl :%s , root node format : %d root node name : %s", mo_node->runtime_property->acl, mo_node->runtime_property->format, mo_node->runtime_property->name);
1968         }
1969
1970         if (mo_parent_path != NULL)
1971                 free(mo_parent_path);
1972
1973         _INNER_FUNC_EXIT;
1974
1975         return mo_node;
1976 }
1977
1978 static sync_agent_dm_mo_error_e _recursive_get_Descendant_MO_List(sync_agent_dm_mo_type_e type, const char *mo_path, sync_agent_dm_mo_node_s * parent_node, int *acc_count, sync_agent_dm_mo_get_option_e option)
1979 {
1980         _INNER_FUNC_ENTER;
1981
1982         int count = 0;
1983         sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
1984         err_code = dm_get_child_mo_list(type, mo_path, &(parent_node->child_node_list), &count, option);
1985         _DEBUG_TRACE("get child mo list err_code_ : %d", err_code);
1986         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
1987                 return err_code;
1988         }
1989         parent_node->child_node_cnt = count;
1990         *acc_count = *acc_count + count;
1991         _DEBUG_TRACE("count : %d", count);
1992         _DEBUG_TRACE("acc count : %d", *acc_count);
1993         _DEBUG_TRACE("MO PAHT : %s", mo_path);
1994
1995         if (mo_path) {
1996                 int i = 0;
1997                 for (; i < count; i++) {
1998                         _DEBUG_TRACE("RJW : %s", parent_node->child_node_list[i].full_path);
1999                         err_code = _recursive_get_Descendant_MO_List(type, parent_node->child_node_list[i].full_path, &(parent_node->child_node_list[i]), acc_count, option);
2000                         _DEBUG_TRACE("err_code : %d", err_code);
2001                         if (err_code != SYNC_AGENT_DM_MO_SUCCESS) {
2002                                 break;
2003                         }
2004                 }
2005         } else {
2006                 return SYNC_AGENT_DM_MO_FAIL;
2007         }
2008
2009         _INNER_FUNC_EXIT;
2010
2011         return err_code;
2012 }
2013
2014 static char *_get_access_type_string(sync_agent_dm_mo_access_type_e access_type)
2015 {
2016         _INNER_FUNC_ENTER;
2017
2018         char *command_str = NULL;
2019
2020         _DEBUG_TRACE("accessType = %d\n", access_type);
2021         switch (access_type) {
2022         case SYNC_AGENT_DM_MO_ACCESSTYPE_ADD:
2023                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_ADD");
2024                 command_str = "Add=";
2025                 break;
2026         case SYNC_AGENT_DM_MO_ACCESSTYPE_COPY:
2027                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_COPY");
2028                 command_str = "Copy=";
2029                 break;
2030         case SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE:
2031                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_DELETE");
2032                 command_str = "Delete=";
2033                 break;
2034         case SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC:
2035                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_EXEC");
2036                 command_str = "Exec=";
2037                 break;
2038         case SYNC_AGENT_DM_MO_ACCESSTYPE_GET:
2039                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_GET");
2040                 command_str = "Get=";
2041                 break;
2042         case SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE:
2043                 _DEBUG_TRACE("SYNC_AGENT_DM_MO_ACCESSTYPE_REPLACE");
2044                 command_str = "Replace=";
2045                 break;
2046         default:
2047                 _DEBUG_TRACE("can not execute logic");
2048                 break;
2049         }
2050         _DEBUG_TRACE("command string = %s\n", command_str);
2051
2052         _INNER_FUNC_EXIT;
2053
2054         return command_str;
2055 }
2056
2057 static sync_agent_dm_mo_error_e __set_MO_RunTimeProperty(char **server_id_list, int server_id_list_cnt, sync_agent_dm_mo_node_s * mo_node)
2058 {
2059         _INNER_FUNC_ENTER;
2060
2061         if (mo_node == NULL || server_id_list == NULL) {
2062                 _DEBUG_ERROR("mo_node == 0 || server_id_list == 0\n");
2063                 return SYNC_AGENT_DM_MO_FAIL;
2064         }
2065
2066         sync_agent_dm_mo_framework_property_s *framework_property = mo_node->framework_property;
2067         sync_agent_dm_mo_runtime_property_s *runtime_property = mo_node->runtime_property;
2068
2069         /* set format, type, type value, title property for framework property */
2070         runtime_property->format = framework_property->dffFormat;
2071         runtime_property->type = framework_property->dfType;
2072
2073         _DEBUG_VERBOSE("FP[dffFormat = %d], RT[format = %d]", framework_property->dffFormat, runtime_property->format);
2074         _DEBUG_VERBOSE("FP[dfType = %d], RT[type = %d]", framework_property->dfType, runtime_property->type);
2075
2076         if (framework_property->dfType_Value != NULL) {
2077                 runtime_property->type_value = strdup(framework_property->dfType_Value);
2078                 _DEBUG_VERBOSE("FP[dfType_Value = %s], RT[type_value = %s]", framework_property->dfType_Value, runtime_property->type_value);
2079         }
2080
2081         if (framework_property->dfTitle != NULL) {
2082                 runtime_property->title = strdup(framework_property->dfTitle);
2083                 _DEBUG_VERBOSE("FP[dfTitle = %s], RT[title = %s]", framework_property->dfTitle, runtime_property->title);
2084         }
2085
2086         /* set name for mo_node */
2087         if (mo_node->name != NULL) {
2088                 runtime_property->name = strdup(mo_node->name);
2089                 _DEBUG_VERBOSE("mo_name[name = %s], RT[name = %s]", mo_node->name, runtime_property->name);
2090         }
2091
2092         /* set version No, size */
2093         runtime_property->verNo = strdup("0");
2094         runtime_property->size = 0;
2095
2096         /* set stamp */
2097         SYNC_AGENT_UTIL_TIME_T current_time;
2098         SYNC_AGENT_UTIL_TIME(&current_time);
2099
2100         SYNC_AGENT_UTIL_TM *time;
2101         time = SYNC_AGENT_UTIL_LOCALTIME(&current_time);
2102
2103         _DEBUG_VERBOSE("year = %d, mon = %d, day = %d, hour = %d, min = %d, sec = %d", time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec);
2104
2105         runtime_property->tStamp = g_strdup_printf("%04d%02d%02dT%02d%02d%02dZ", time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec);
2106         _DEBUG_VERBOSE("RT[tStamp = %s]", runtime_property->tStamp);
2107
2108         /* set ACL */
2109         if (runtime_property->acl != NULL) {
2110                 /*aready this is setted runtime property acl */
2111                 _INNER_FUNC_EXIT;
2112                 return SYNC_AGENT_DM_MO_SUCCESS;
2113         }
2114
2115         int total_acl_size = 0;
2116         if (server_id_list_cnt > 0) {
2117
2118                 int i, j;
2119                 for (i = 0; i < server_id_list_cnt; i++) {
2120                         if (server_id_list[i] == NULL) {
2121                                 _DEBUG_ERROR("server_id_list[%d] == NULL", i);
2122                                 return SYNC_AGENT_DM_MO_FAIL;
2123                         }
2124                         _DEBUG_VERBOSE("server_id_list[%d] = %s, length = %d", i, server_id_list[i], strlen(server_id_list[i]));
2125                         total_acl_size += ((10 * DEVICE_MANAGER_MO_ACCESSTYPE_CNT) + strlen(server_id_list[i]));
2126                 }
2127
2128                 char *total_acl_value = (char *)calloc(total_acl_size, sizeof(char));
2129                 if (total_acl_value == NULL) {
2130                         _DEBUG_ERROR("CALLOC failed !!!");
2131                         return SYNC_AGENT_DM_MO_FAIL;
2132                 }
2133                 int total_acl_value_idx = 0;
2134
2135                 sync_agent_dm_mo_access_type_e access_type = SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET;
2136                 char *command_str = NULL;
2137
2138                 int temp_acl_value_size = 0;
2139                 char *temp_acl_value = NULL;
2140
2141                 int mul = 1;
2142                 for (i = 1; i <= DEVICE_MANAGER_MO_ACCESSTYPE_CNT; i++) {
2143
2144                         _DEBUG_VERBOSE("framework_property->accessType = %d\n", framework_property->accessType);
2145                         if (framework_property->accessType != SYNC_AGENT_DM_MO_ACCESSTYPE_NO_SET) {
2146
2147                                 access_type = framework_property->accessType & (mul);
2148                                 _DEBUG_VERBOSE("accessType = %d\n", access_type);
2149                                 command_str = _get_access_type_string(access_type);
2150
2151                                 if (command_str != NULL) {
2152                                         for (j = 0; j < server_id_list_cnt; j++) {
2153
2154                                                 _DEBUG_VERBOSE("server_id_list[%d] = %s", j, server_id_list[j]);
2155                                                 if (i == DEVICE_MANAGER_MO_ACCESSTYPE_CNT && j == server_id_list_cnt - 1) {
2156                                                         temp_acl_value = g_strdup_printf("%s%s", command_str, server_id_list[j]);
2157                                                 } else {
2158                                                         temp_acl_value = g_strdup_printf("%s%s&", command_str, server_id_list[j]);
2159                                                 }
2160
2161                                                 temp_acl_value_size = strlen(temp_acl_value);
2162
2163                                                 _DEBUG_VERBOSE("temp_acl_value = %s\n", temp_acl_value);
2164                                                 memcpy(total_acl_value + total_acl_value_idx, temp_acl_value, temp_acl_value_size);
2165                                                 total_acl_value_idx += temp_acl_value_size;
2166                                         }
2167                                 }
2168                         } else {
2169                                 break;
2170                         }
2171
2172                         mul *= 2;
2173                 }
2174
2175                 _DEBUG_VERBOSE("total_acl_value = %s\n", total_acl_value);
2176                 runtime_property->acl = total_acl_value;
2177         }
2178
2179         _INNER_FUNC_EXIT;
2180
2181         return SYNC_AGENT_DM_MO_SUCCESS;
2182 }
2183
2184 static sync_agent_dm_mo_error_e _add_MO_Tree(sync_agent_dm_mo_type_e mo_type, sync_agent_dm_mo_node_s * mo_node, plugin_get_mo_value_cb func_point_get_value, char **server_id_list, int server_id_list_cnt, int server_type)
2185 {
2186         _INNER_FUNC_ENTER;
2187
2188         sync_agent_dm_mo_error_e err = SYNC_AGENT_DM_MO_SUCCESS;
2189
2190         if (mo_node == NULL) {
2191                 return SYNC_AGENT_DM_MO_FAIL;
2192         }
2193
2194         _DEBUG_TRACE("[%s] [%s] [%d] [%d]", mo_node->name, mo_node->full_path, mo_node->type, mo_node->child_node_cnt);
2195         _DEBUG_TRACE("[%d] [%s] [%d] [%d] [%d] [%s] [%d]", mo_node->framework_property->accessType, mo_node->framework_property->description, mo_node->framework_property->dffFormat, mo_node->framework_property->occurrence,
2196                      mo_node->framework_property->scope, mo_node->framework_property->dfTitle, mo_node->framework_property->dfType);
2197         _DEBUG_TRACE("================================================================================");
2198
2199         /*
2200          * Setting acl of RuntimeProperty in PlugIn
2201          */
2202
2203         /*
2204          * Set MO Value from PlugIn
2205          */
2206         if (func_point_get_value != NULL) {
2207                 func_point_get_value(mo_node->full_path, mo_node->name, &(mo_node->value));
2208                 _DEBUG_TRACE("mo value [%s] ", mo_node->value);
2209         }
2210
2211         mo_node->server_type = server_type;
2212         err = dm_mo_add_node_wraper(mo_type, mo_node);
2213         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2214                 _DEBUG_ERROR("Failed dm_mo_add_node_wraper() : [%d]", err);
2215                 return err;
2216         }
2217         err = dm_mo_add_framework_property_wraper(mo_node->id, mo_node->framework_property);
2218         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2219                 _DEBUG_ERROR("Failed dm_mo_add_framework_property_wraper() : [%d]", err);
2220                 return err;
2221         }
2222
2223         _DEBUG_TRACE("set_mo_run Start");
2224         err = __set_MO_RunTimeProperty(server_id_list, server_id_list_cnt, mo_node);
2225         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2226                 _DEBUG_ERROR("Failed __set_MO_RunTimeProperty() : [%d]", err);
2227                 return err;
2228         }
2229
2230         _DEBUG_TRACE("set_mo_run ENd");
2231         err = dm_mo_add_runtime_property_wraper(mo_node->id, mo_node->runtime_property);
2232         if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2233                 _DEBUG_ERROR("Failed dm_mo_add_runtime_property_wraper() : [%d]", err);
2234                 return err;
2235         }
2236
2237         sync_agent_dm_mo_node_s *pCursor = mo_node->child_node_list;
2238         while (pCursor != NULL) {
2239                 pCursor->parent_id = mo_node->id;
2240
2241                 err = _add_MO_Tree(mo_type, pCursor, func_point_get_value, server_id_list, server_id_list_cnt, server_type);
2242                 if (err != SYNC_AGENT_DM_MO_SUCCESS) {
2243                         return err;
2244                 }
2245
2246                 pCursor = pCursor->next_node;
2247         }
2248
2249         _INNER_FUNC_EXIT;
2250
2251         return err;
2252 }
2253
2254 /*
2255 static void __print_Tree(sync_agent_dm_mo_node_s * root_ptr, int depth)
2256 {
2257         if (root_ptr == NULL) {
2258                 return;
2259         }
2260 //      int i = 0;
2261 //      for ( ; i < depth; i++) {
2262 //              _DEBUG_INFO("\t");
2263 //      }
2264         _DEBUG_INFO("[%s] [%s] [%d] [%d]", root_ptr->name, root_ptr->full_path, root_ptr->type, root_ptr->child_node_cnt);
2265         _DEBUG_INFO("[%d] [%s] [%d] [%d] [%d] [%s] [%d]", root_ptr->framework_property->accessType, root_ptr->framework_property->description, root_ptr->framework_property->dffFormat, root_ptr->framework_property->occurrence, root_ptr->framework_property->scope, root_ptr->framework_property->dfTitle, root_ptr->framework_property->dfType);
2266         _DEBUG_INFO("================================================================================");
2267
2268         sync_agent_dm_mo_node_s *pCursor = root_ptr->child_node_list;
2269         while (pCursor != NULL) {
2270                 __print_Tree(pCursor, depth + 1);
2271                 pCursor = pCursor->next_node;
2272         }
2273 }
2274 */