3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include "utility/sync_util.h"
21 #include "utility/fw_alloc.h"
22 #include "device-manager/mo_database_handler.h"
23 #include "device-manager/mo_database.h"
25 #ifndef SYNC_AGENT_LOG
27 #define LOG_TAG "AF_MO"
30 /* static function define */
31 static int _busy_handler(void *pData, int count);
32 static sync_agent_dm_mo_error_e _query_exec(SYNC_AGENT_DA_MO_HANDLER * mo_handler, char *query, char *err_msg);
33 static daci_stmt _query_prepare(SYNC_AGENT_DA_MO_HANDLER * mo_handler, char *query, int size);
34 static sync_agent_da_return_e _stmt_bind_text(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index, const char *value);
35 static sync_agent_dm_mo_error_e _stmt_bind_int(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index, const int value);
36 static sync_agent_dm_mo_error_e __stmt_bind_null(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index);
37 static sync_agent_da_return_e _stmt_step(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt);
38 static sync_agent_dm_mo_error_e _stmt_finalize(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt);
39 static char *_stmt_column_text(daci_stmt stmt, int index);
40 static int _stmt_column_int(daci_stmt stmt, int index);
41 static sync_agent_dm_mo_error_e _get_table(SYNC_AGENT_DA_MO_HANDLER * mo_handler, char *query, char ***result, int *row_count, int *col_count);
42 static void _free_table(char **result);
44 static int _exist_table(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *table_name);
45 static int _last_insert_id(SYNC_AGENT_DA_MO_HANDLER * mo_handler);
47 static char *_extract_dmacc_name(const char *mo_full_path);
49 static char *__create_table[] = {
50 /* 1. create node_tbl */
51 "create table node_tbl "
52 "( " "node_id integer primary key autoincrement, " "name varchar(100) not null, " "value varchar(100) default null, " "parent_node_id integer default null, " "full_path varchar(200) not null, " "node_type integer not null, "
53 "mo_type integer not null, " "server_type integer default null, " "constraint node_tbl_parent_node_id_fk foreign key(parent_node_id) references node_tbl(node_id), " "constraint node_tbl_unique_key unique(full_path, mo_type, server_type) " ");",
55 /* 2. create framework_property_tbl */
56 "create table framework_property_tbl "
58 "framework_property_id integer primary key autoincrement, "
59 "access_type integer default null, "
60 "default_value varchar(100) default null, " "description varchar(100) default null, " "df_format integer default null, " "occurrence integer default null, " "occurrence_num integer default null, " "scope integer default null, "
61 "df_title varchar(100) default null, " "df_type integer default null, " "df_type_value varchar(20) default null, " "node_id integer not null unique, "
62 "constraint framework_property_tbl_node_id_fk foreign key(node_id) references node_tbl(node_id) " ");",
64 /* 3. create runtime_property_tbl */
65 "create table runtime_property_tbl "
67 "runtime_property_id integer primary key autoincrement, "
68 "acl varchar(100) default null, " "format integer default null, " "name varchar(100) default null, " "size varchar(100) default null, " "title varchar(100) default null, " "t_stamp varchar(100) default null, " "type integer default null, "
69 "type_value varchar(30) default null, " "ver_no varchar(100) default null, " "node_id integer not null unique, " "constraint runtime_property_tbl_node_id_fk foreign key(node_id) references node_tbl(node_id) " ");",
73 sync_agent_dm_mo_error_e dm_mo_begin_transaction(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
77 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
79 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
81 ret = _query_exec(mo_handler, "begin immediate", "begin_transaction failed");
83 /* if (ret == SYNC_AGENT_DA_ERR_QUERY_FAILED)
84 ret = SYNC_AGENT_DA_ERR_TRANSACTION_FAILED;*/
91 sync_agent_dm_mo_error_e dm_mo_end_transaction(SYNC_AGENT_DA_MO_HANDLER * mo_handler, sync_agent_da_transaction_e transaction)
95 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
97 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
101 if (transaction == SYNC_AGENT_DA_TRANSACTION_COMMIT) {
102 query = "commit transaction";
103 err_msg = "commit_transaction failed";
104 } else if (transaction == SYNC_AGENT_DA_TRANSACTION_ROLLBACK) {
105 query = "rollback transaction";
106 err_msg = "rollback_transaction failed";
109 ret = _query_exec(mo_handler, query, err_msg);
110 if (ret == SYNC_AGENT_DM_MO_FAIL) {
111 if (transaction == SYNC_AGENT_DA_TRANSACTION_COMMIT) {
112 query = "rollback transaction";
113 err_msg = "rollback_transaction failed";
114 ret = _query_exec(mo_handler, query, err_msg);
115 if (ret == SYNC_AGENT_DM_MO_SUCCESS)
116 _DEBUG_INFO("rollback_transaction success");
118 ret = SYNC_AGENT_DM_MO_FAIL;
126 sync_agent_dm_mo_error_e mo_open_agent(SYNC_AGENT_DA_MO_HANDLER ** mo_handler, char *database_path)
130 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
133 char *err_msg = NULL;
135 if (*mo_handler == NULL) {
138 /* ret = db_util_open(DACI_FILE_PATH, &(*t_daci_handler), 0); */
140 ret = sqlite3_open(database_path, mo_handler);
141 if (ret != SQLITE_OK)
144 /* register busy handler */
145 ret = sqlite3_busy_handler(*mo_handler, _busy_handler, 0);
146 if (ret != SQLITE_OK) {
147 _DEBUG_INFO("fail to register busy handler", err_msg);
151 /* enable persist journal mode */
152 ret = sqlite3_exec(*mo_handler, "PRAGMA journal_mode = PERSIST", 0, 0, &err_msg);
153 if (ret != SQLITE_OK) {
154 _DEBUG_INFO("fail to change journal mode: %s", err_msg);
158 _DEBUG_INFO("mo_db_open success");
161 _DEBUG_INFO("mo_db_already opened");
166 return SYNC_AGENT_DM_MO_SUCCESS;
170 _DEBUG_ERROR("agent_db_open failed(%d) : %s", ret, sqlite3_errmsg(*mo_handler));
173 sqlite3_free(err_msg);
175 sqlite3_close(*mo_handler);
178 return SYNC_AGENT_DM_MO_FAIL;
181 sync_agent_dm_mo_error_e mo_close_agent(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
185 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
188 ret = sqlite3_close(mo_handler);
191 if (ret != SQLITE_OK) {
192 _DEBUG_ERROR("mo_db_close failed(%d) : %s", ret, sqlite3_errmsg(mo_handler));
193 return SYNC_AGENT_DM_MO_FAIL;
196 _DEBUG_INFO("mo_db_close success");
200 return SYNC_AGENT_DM_MO_SUCCESS;
203 sync_agent_dm_mo_error_e dm_mo_create_mo_table(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
207 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
209 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
211 if (mo_handler == NULL) {
212 _DEBUG_INFO("[%s] sync_agent_dm_mo_error_e !\n", __func__);
213 return SYNC_AGENT_DM_MO_FAIL;
216 if ((dm_mo_begin_transaction(mo_handler) != SYNC_AGENT_DM_MO_SUCCESS)) {
217 _DEBUG_ERROR("mo_db_default_tbl_create failed");
218 return SYNC_AGENT_DM_MO_FAIL;
221 /* 1. create node_tbl */
222 if (_exist_table(mo_handler, "node_tbl") == 0) {
223 ret = _query_exec(mo_handler, __create_table[0], "node_tbl_create failed");
224 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
228 /* 2. create framework_property_tbl */
229 if (_exist_table(mo_handler, "framework_property_tbl") == 0) {
230 ret = _query_exec(mo_handler, __create_table[1], "framework_property_tbl_create failed");
231 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
235 /* 3. create runtime_property_tbl */
236 if (_exist_table(mo_handler, "runtime_property_tbl") == 0) {
237 ret = _query_exec(mo_handler, __create_table[2], "runtime_property_tbl_create failed");
238 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
244 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
245 dm_mo_end_transaction(mo_handler, SYNC_AGENT_DA_TRANSACTION_ROLLBACK);
246 ret = SYNC_AGENT_DM_MO_FAIL;
248 ret = dm_mo_end_transaction(mo_handler, SYNC_AGENT_DA_TRANSACTION_COMMIT);
256 sync_agent_dm_mo_error_e dm_mo_add_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler, sync_agent_dm_mo_type_e mo_type, sync_agent_dm_mo_node_s * mo_node)
260 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
261 retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
263 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
264 daci_stmt stmt = NULL;
267 query = "insert into node_tbl (name, value, parent_node_id, full_path, node_type, mo_type, server_type) values (?, ?, ?, ?, ?, ?, ?)";
269 stmt = _query_prepare(mo_handler, query, strlen(query));
271 ret = SYNC_AGENT_DM_MO_FAIL;
275 /* _stmt_bind_int(mo_handler, stmt, 1, mo_node->id);*/
276 _stmt_bind_text(mo_handler, stmt, 1, mo_node->name);
277 _stmt_bind_text(mo_handler, stmt, 2, mo_node->value);
278 _stmt_bind_int(mo_handler, stmt, 3, mo_node->parent_id);
279 _stmt_bind_text(mo_handler, stmt, 4, mo_node->full_path);
280 _stmt_bind_int(mo_handler, stmt, 5, mo_node->type);
281 _stmt_bind_int(mo_handler, stmt, 6, mo_type);
282 _stmt_bind_int(mo_handler, stmt, 7, mo_node->server_type);
284 ret = _stmt_step(mo_handler, stmt);
285 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
286 ret = SYNC_AGENT_DM_MO_FAIL;
291 _stmt_finalize(mo_handler, stmt);
293 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
296 mo_node->id = _last_insert_id(mo_handler);
304 sync_agent_dm_mo_error_e dm_mo_delete_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id)
308 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
310 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
311 daci_stmt stmt = NULL;
314 query = "delete from node_tbl where node_id = ?";
316 stmt = _query_prepare(mo_handler, query, strlen(query));
318 ret = SYNC_AGENT_DM_MO_FAIL;
322 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
323 ret = _stmt_step(mo_handler, stmt);
328 _stmt_finalize(mo_handler, stmt);
335 sync_agent_dm_mo_error_e dm_mo_update_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler, sync_agent_dm_mo_type_e mo_type, const char *path, const sync_agent_dm_mo_node_s * mo_node)
339 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
340 retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
342 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
343 daci_stmt stmt = NULL;
346 query = "update node_tbl set value = ? where full_path = ? and mo_type = ?";
348 stmt = _query_prepare(mo_handler, query, strlen(query));
350 ret = SYNC_AGENT_DM_MO_FAIL;
354 _stmt_bind_text(mo_handler, stmt, 1, mo_node->value);
355 _stmt_bind_text(mo_handler, stmt, 2, path);
356 _stmt_bind_int(mo_handler, stmt, 3, mo_type);
358 ret = _stmt_step(mo_handler, stmt);
362 _stmt_finalize(mo_handler, stmt);
369 sync_agent_dm_mo_error_e dm_mo_get_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *path, sync_agent_dm_mo_node_s ** mo_node)
373 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
375 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
376 daci_stmt stmt = NULL;
377 char *query = "select * from node_tbl where full_path = ?";
378 sync_agent_dm_mo_node_s *temp_mo_node = NULL;
380 stmt = _query_prepare(mo_handler, query, strlen(query));
383 _stmt_bind_text(mo_handler, stmt, 1, path);
384 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
385 temp_mo_node = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_node_s *, sizeof(sync_agent_dm_mo_node_s), 1);
386 temp_mo_node->id = _stmt_column_int(stmt, 0);
387 temp_mo_node->name = _stmt_column_text(stmt, 1);
388 temp_mo_node->value = _stmt_column_text(stmt, 2);
389 temp_mo_node->parent_id = _stmt_column_int(stmt, 3);
390 temp_mo_node->full_path = _stmt_column_text(stmt, 4);
391 temp_mo_node->type = _stmt_column_int(stmt, 5);
392 temp_mo_node->mo_type = _stmt_column_int(stmt, 6);
393 temp_mo_node->server_type = _stmt_column_int(stmt, 7);
394 temp_mo_node->runtime_property = 0;
395 temp_mo_node->framework_property = 0;
397 ret = SYNC_AGENT_DM_MO_FAIL;
399 ret = _stmt_finalize(mo_handler, stmt);
401 ret = SYNC_AGENT_DM_MO_FAIL;
404 (*mo_node) = temp_mo_node;
411 sync_agent_dm_mo_error_e dm_mo_get_nodes(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *path, sync_agent_dm_mo_node_s ** mo_node)
415 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
417 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
418 daci_stmt stmt = NULL;
419 char *query = "select * from node_tbl where full_path = ?";
420 sync_agent_dm_mo_node_s *current_ptr = NULL;
422 stmt = _query_prepare(mo_handler, query, strlen(query));
424 _stmt_bind_text(mo_handler, stmt, 1, path);
426 while (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
427 _DEBUG_INFO("nodes called!!!");
428 sync_agent_dm_mo_node_s *temp_mo_node = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_node_s *, sizeof(sync_agent_dm_mo_node_s), 1);
429 if (temp_mo_node == NULL) {
430 _DEBUG_ERROR("CALLOC failed !!!");
431 return SYNC_AGENT_DM_MO_FAIL;
433 temp_mo_node->id = _stmt_column_int(stmt, 0);
434 temp_mo_node->name = _stmt_column_text(stmt, 1);
435 temp_mo_node->value = _stmt_column_text(stmt, 2);
436 temp_mo_node->parent_id = _stmt_column_int(stmt, 3);
437 temp_mo_node->full_path = _stmt_column_text(stmt, 4);
438 temp_mo_node->type = _stmt_column_int(stmt, 5);
439 temp_mo_node->mo_type = _stmt_column_int(stmt, 6);
440 temp_mo_node->server_type = _stmt_column_int(stmt, 7);
441 temp_mo_node->runtime_property = 0;
442 temp_mo_node->framework_property = 0;
443 if (current_ptr == NULL) {
444 _DEBUG_INFO("nodes first node!!!");
445 (*mo_node) = temp_mo_node;
446 current_ptr = (*mo_node);
448 _DEBUG_INFO("nodes next node!!!");
449 current_ptr->next_node = temp_mo_node;
450 current_ptr = temp_mo_node;
453 ret = _stmt_finalize(mo_handler, stmt);
455 ret = SYNC_AGENT_DM_MO_FAIL;
463 sync_agent_dm_mo_error_e dm_mo_is_exist_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *path)
467 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
468 retvm_if(path == NULL, SYNC_AGENT_DM_MO_FAIL, "path is NULL !!");
470 _DEBUG_INFO("[%s] Start path : %s\n", __func__, path);
472 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
473 daci_stmt stmt = NULL;
475 char query[1024] = { 0, };
477 snprintf(query, sizeof(query), "select count(*) from node_tbl where full_path = \'%s\' ", path);
479 stmt = _query_prepare(mo_handler, query, strlen(query));
481 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA)
482 data_count = _stmt_column_int(stmt, 0);
484 _stmt_finalize(mo_handler, stmt);
487 if (data_count == 0) {
488 ret = SYNC_AGENT_DM_MO_NOT_EXIST_NODE;
490 ret = SYNC_AGENT_DM_MO_EXIST_NODE;
498 sync_agent_dm_mo_error_e dm_mo_get_child_node(sync_agent_dm_mo_type_e mo_type, SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *path, sync_agent_dm_mo_node_s ** mo_node, int *count)
502 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
503 retvm_if(path == NULL, SYNC_AGENT_DM_MO_FAIL, "path is NULL !!");
505 _DEBUG_INFO("[%s] Start ! mopath : %s , mo type : %d\n", __func__, path, mo_type);
507 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_FAIL; // SYNC_AGENT_DM_MO_SUCCESS;
508 sync_agent_dm_mo_node_s *temp_mo_node = NULL;
509 char **result = NULL;
514 char query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = { 0, };
516 if (!strcmp(path, ".")) {
517 snprintf(query, sizeof(query), "select * from node_tbl where parent_node_id in " "(select node_id from node_tbl where full_path = \'%s\')", path);
518 ret = _get_table(mo_handler, query, &result, &row_count, &col_count);
519 if (result == NULL) {
520 _DEBUG_ERROR("result is NULL!!");
521 ret = SYNC_AGENT_DM_MO_FAIL;
525 snprintf(query, sizeof(query), "select * from node_tbl where parent_node_id in " "(select node_id from node_tbl where mo_type = %d and full_path = \'%s\')", mo_type, path);
526 ret = _get_table(mo_handler, query, &result, &row_count, &col_count);
527 if (result == NULL) {
528 _DEBUG_ERROR("result is NULL!!");
529 ret = SYNC_AGENT_DM_MO_FAIL;
534 if ((ret == SYNC_AGENT_DM_MO_SUCCESS) && (row_count != 0)) {
536 temp_mo_node = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_node_s *, sizeof(sync_agent_dm_mo_node_s), row_count);
537 if (temp_mo_node == NULL) {
538 _DEBUG_ERROR("memory_allocation failed");
539 ret = SYNC_AGENT_DM_MO_FAIL;
543 for (i = 0; i < row_count; i++) {
544 temp_mo_node[i].id = SYNC_AGENT_DA_ATOI(result[index]);
546 temp_mo_node[i].name = SYNC_AGENT_DA_STRDUP(result[index]);
548 temp_mo_node[i].value = SYNC_AGENT_DA_STRDUP(result[index]);
550 temp_mo_node[i].parent_id = SYNC_AGENT_DA_ATOI(result[index]);
552 temp_mo_node[i].full_path = SYNC_AGENT_DA_STRDUP(result[index]);
554 temp_mo_node[i].type = SYNC_AGENT_DA_ATOI(result[index]);
556 temp_mo_node[i].mo_type = SYNC_AGENT_DA_ATOI(result[index]);
558 temp_mo_node[i].server_type = SYNC_AGENT_DA_ATOI(result[index]);
562 ret = SYNC_AGENT_DM_MO_SUCCESS;
566 (*mo_node) = temp_mo_node;
570 ret = SYNC_AGENT_DM_MO_FAIL;
578 //(*mo_node) = temp_mo_node;
585 sync_agent_dm_mo_error_e dm_mo_delete_all_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
589 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
591 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
592 daci_stmt stmt = NULL;
595 query = "delete from node_tbl";
597 stmt = _query_prepare(mo_handler, query, strlen(query));
599 ret = SYNC_AGENT_DM_MO_FAIL;
602 ret = _stmt_step(mo_handler, stmt);
607 _stmt_finalize(mo_handler, stmt);
614 sync_agent_dm_mo_type_e dm_mo_get_mo_type(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *mo_full_path)
618 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_TYPE_NO_TYPE, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
619 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_TYPE_NO_TYPE, "mo_full_path is NULL !!");
621 sync_agent_dm_mo_type_e mo_type = SYNC_AGENT_DM_MO_TYPE_NO_TYPE;
622 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
623 daci_stmt stmt = NULL;
624 char *query = "select mo_type from node_tbl where full_path = ?";
626 stmt = _query_prepare(mo_handler, query, strlen(query));
629 _stmt_bind_text(mo_handler, stmt, 1, mo_full_path);
630 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
631 mo_type = _stmt_column_int(stmt, 0);
633 ret = _stmt_finalize(mo_handler, stmt);
635 ret = SYNC_AGENT_DM_MO_FAIL;
643 sync_agent_dm_mo_error_e dm_mo_get_node_from_id(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id, sync_agent_dm_mo_node_s ** mo_node)
647 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
649 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
650 daci_stmt stmt = NULL;
651 char *query = "select * from node_tbl where node_id = ?";
652 sync_agent_dm_mo_node_s *temp_mo_node = NULL;
654 stmt = _query_prepare(mo_handler, query, strlen(query));
657 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
658 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
659 temp_mo_node = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_node_s *, sizeof(sync_agent_dm_mo_node_s), 1);
660 temp_mo_node->id = _stmt_column_int(stmt, 0);
661 temp_mo_node->name = _stmt_column_text(stmt, 1);
662 temp_mo_node->value = _stmt_column_text(stmt, 2);
663 temp_mo_node->parent_id = _stmt_column_int(stmt, 3);
664 temp_mo_node->full_path = _stmt_column_text(stmt, 4);
665 temp_mo_node->type = _stmt_column_int(stmt, 5);
666 temp_mo_node->mo_type = _stmt_column_int(stmt, 6);
667 temp_mo_node->server_type = _stmt_column_int(stmt, 7);
668 temp_mo_node->runtime_property = 0;
669 temp_mo_node->framework_property = 0;
671 ret = _stmt_finalize(mo_handler, stmt);
673 ret = SYNC_AGENT_DM_MO_FAIL;
676 (*mo_node) = temp_mo_node;
683 sync_agent_dm_mo_error_e dm_mo_get_acc_info(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *server_id, const char *server_id_string, const char *acc_type_string, sync_agent_dm_acc_info_s ** acc_info)
687 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
688 retvm_if(server_id == NULL, SYNC_AGENT_DM_MO_FAIL, "server id is NULL !!");
689 retvm_if(server_id_string == NULL, SYNC_AGENT_DM_MO_FAIL, "server id string is NULL !!");
690 retvm_if(acc_type_string == NULL, SYNC_AGENT_DM_MO_FAIL, "acc type string is NULL !!");
692 _DEBUG_INFO("get acc type string : %s ", acc_type_string);
693 _DEBUG_INFO("get acc server id string : %s ", server_id_string);
694 _DEBUG_INFO("get acc server id : %s ", server_id);
696 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
697 daci_stmt stmt = NULL;
698 char *query = "select full_path from node_tbl where name = ? and value = ? and mo_type = ?";
699 char *full_path = NULL;
701 stmt = _query_prepare(mo_handler, query, strlen(query));
704 _stmt_bind_text(mo_handler, stmt, 1, server_id_string);
705 _stmt_bind_text(mo_handler, stmt, 2, server_id);
706 _stmt_bind_int(mo_handler, stmt, 3, SYNC_AGENT_DM_MO_TYPE_DMACC);
707 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
708 full_path = _stmt_column_text(stmt, 0);
710 ret = _stmt_finalize(mo_handler, stmt);
712 ret = SYNC_AGENT_DM_MO_FAIL;
715 _DEBUG_INFO("full_path : %s", full_path);
716 if (full_path == NULL) {
717 return SYNC_AGENT_DM_MO_FAIL;
720 * Parsing full_path and extract dmacc name
722 char *dmacc_name = _extract_dmacc_name(full_path);
723 _DEBUG_INFO("dmacc_name : %s", dmacc_name);
725 if (dmacc_name == NULL) {
726 return SYNC_AGENT_DM_MO_FAIL;
729 *acc_info = (sync_agent_dm_acc_info_s *) calloc(1, sizeof(sync_agent_dm_acc_info_s));
730 if (*acc_info == NULL) {
731 _DEBUG_ERROR("CALLOC failed !!!");
732 return SYNC_AGENT_DM_MO_FAIL;
738 char query01[2048] = { 0, };
739 snprintf(query01, sizeof(query01), "select value from node_tbl where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", "AAuthName", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name, acc_type_string);
741 stmt = _query_prepare(mo_handler, query01, strlen(query01));
743 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
744 (*acc_info)->auth_name = _stmt_column_text(stmt, 0);
746 ret = _stmt_finalize(mo_handler, stmt);
748 ret = SYNC_AGENT_DM_MO_FAIL;
754 char query02[2048] = { 0, };
755 snprintf(query02, sizeof(query02), "select value from node_tbl where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", "AAuthSecret", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name, acc_type_string);
757 stmt = _query_prepare(mo_handler, query02, strlen(query02));
759 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
760 (*acc_info)->auth_secret = _stmt_column_text(stmt, 0);
762 ret = _stmt_finalize(mo_handler, stmt);
764 ret = SYNC_AGENT_DM_MO_FAIL;
770 char query03[2048] = { 0, };
771 snprintf(query03, sizeof(query03), "select value from node_tbl where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", "AAuthLevel", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name, acc_type_string);
773 stmt = _query_prepare(mo_handler, query03, strlen(query03));
775 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
776 (*acc_info)->auth_level = _stmt_column_text(stmt, 0);
778 ret = _stmt_finalize(mo_handler, stmt);
780 ret = SYNC_AGENT_DM_MO_FAIL;
786 char query04[2048] = { 0, };
787 snprintf(query04, sizeof(query04), "select value from node_tbl where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", "AAuthData", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name, acc_type_string);
789 stmt = _query_prepare(mo_handler, query04, strlen(query04));
791 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
792 (*acc_info)->auth_data = _stmt_column_text(stmt, 0);
794 ret = _stmt_finalize(mo_handler, stmt);
796 ret = SYNC_AGENT_DM_MO_FAIL;
802 char query05[2048] = { 0, };
803 snprintf(query05, sizeof(query05), "select value from node_tbl where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", "AAuthType", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name, acc_type_string);
805 stmt = _query_prepare(mo_handler, query05, strlen(query05));
807 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
808 (*acc_info)->auth_type = _stmt_column_text(stmt, 0);
810 ret = _stmt_finalize(mo_handler, stmt);
812 ret = SYNC_AGENT_DM_MO_FAIL;
818 char query06[2048] = { 0, };
819 snprintf(query06, sizeof(query06), "select value from node_tbl where name = '%s' and mo_type = %d and full_path like '\%%%s\%%'", "Addr", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name);
821 stmt = _query_prepare(mo_handler, query06, strlen(query06));
823 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
824 (*acc_info)->addr = _stmt_column_text(stmt, 0);
826 ret = _stmt_finalize(mo_handler, stmt);
828 ret = SYNC_AGENT_DM_MO_FAIL;
831 if (dmacc_name != NULL) {
835 _DEBUG_INFO("[%s] End !\n", __func__);
842 sync_agent_dm_mo_error_e dm_mo_set_acc_info(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *server_id, const char *server_id_string, const char *acc_type_string, sync_agent_dm_acc_info_s * acc_info)
846 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
847 retvm_if(server_id == NULL, SYNC_AGENT_DM_MO_FAIL, "server id is NULL !!");
848 retvm_if(server_id_string == NULL, SYNC_AGENT_DM_MO_FAIL, "server id string is NULL !!");
849 retvm_if(acc_type_string == NULL, SYNC_AGENT_DM_MO_FAIL, "acc type string is NULL !!");
850 retvm_if(acc_info == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_acc_info_s is NULL !!");
852 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
854 daci_stmt stmt = NULL;
855 char *query = "select full_path from node_tbl where name = ? and value = ? and mo_type = ?";
856 char *full_path = NULL;
858 stmt = _query_prepare(mo_handler, query, strlen(query));
861 _stmt_bind_text(mo_handler, stmt, 1, server_id_string);
862 _stmt_bind_text(mo_handler, stmt, 2, server_id);
863 _stmt_bind_int(mo_handler, stmt, 3, SYNC_AGENT_DM_MO_TYPE_DMACC);
864 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
865 full_path = _stmt_column_text(stmt, 0);
867 ret = _stmt_finalize(mo_handler, stmt);
869 ret = SYNC_AGENT_DM_MO_FAIL;
872 _DEBUG_INFO("full_path : %s", full_path);
875 * Parsing full_path and extract dmacc name
877 char *dmacc_name = _extract_dmacc_name(full_path);
878 _DEBUG_INFO("dmacc_name : %s", dmacc_name);
880 if (dmacc_name == NULL) {
881 return SYNC_AGENT_DM_MO_FAIL;
887 char query01[2048] = { 0, };
888 snprintf(query01, sizeof(query01), "update node_tbl set value = '%s' where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", acc_info->auth_name, "AAuthName", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name,
891 stmt = _query_prepare(mo_handler, query01, strlen(query01));
893 ret = _stmt_step(mo_handler, stmt);
895 ret = _stmt_finalize(mo_handler, stmt);
897 ret = SYNC_AGENT_DM_MO_FAIL;
903 char query02[2048] = { 0, };
904 snprintf(query02, sizeof(query02), "update node_tbl set value = '%s' where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", acc_info->auth_secret, "AAuthSecret", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name,
907 stmt = _query_prepare(mo_handler, query02, strlen(query02));
909 ret = _stmt_step(mo_handler, stmt);
911 ret = _stmt_finalize(mo_handler, stmt);
913 ret = SYNC_AGENT_DM_MO_FAIL;
919 char query03[2048] = { 0, };
920 snprintf(query03, sizeof(query03), "update node_tbl set value = '%s' where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", acc_info->auth_level, "AAuthLevel", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name,
923 stmt = _query_prepare(mo_handler, query03, strlen(query03));
925 ret = _stmt_step(mo_handler, stmt);
927 ret = _stmt_finalize(mo_handler, stmt);
929 ret = SYNC_AGENT_DM_MO_FAIL;
935 char query04[2048] = { 0, };
936 snprintf(query04, sizeof(query04), "update node_tbl set value = '%s' where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", acc_info->auth_data, "AAuthData", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name,
939 stmt = _query_prepare(mo_handler, query04, strlen(query04));
941 ret = _stmt_step(mo_handler, stmt);
943 ret = _stmt_finalize(mo_handler, stmt);
945 ret = SYNC_AGENT_DM_MO_FAIL;
951 char query05[2048] = { 0, };
952 snprintf(query05, sizeof(query05), "update node_tbl set value = '%s' where name = '%s' and mo_type = %d and full_path like '\%%%s\%%' and full_path like '\%%%s\%%'", acc_info->auth_type, "AAuthType", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name,
955 stmt = _query_prepare(mo_handler, query05, strlen(query05));
957 ret = _stmt_step(mo_handler, stmt);
959 ret = _stmt_finalize(mo_handler, stmt);
961 ret = SYNC_AGENT_DM_MO_FAIL;
967 char query06[2048] = { 0, };
968 snprintf(query06, sizeof(query06), "update node_tbl set value = '%s' where name = '%s' and mo_type = %d and full_path like '\%%%s\%%'", acc_info->addr, "Addr", SYNC_AGENT_DM_MO_TYPE_DMACC, dmacc_name);
970 stmt = _query_prepare(mo_handler, query06, strlen(query06));
972 ret = _stmt_step(mo_handler, stmt);
974 ret = _stmt_finalize(mo_handler, stmt);
976 ret = SYNC_AGENT_DM_MO_FAIL;
979 if (dmacc_name != NULL) {
988 sync_agent_dm_mo_error_e dm_mo_get_server_id_list(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *server_id_string, sync_agent_dm_server_info_s ** head_ptr)
992 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
993 retvm_if(server_id_string == NULL, SYNC_AGENT_DM_MO_FAIL, "server id string is NULL !!");
995 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
996 sync_agent_dm_server_info_s *current_ptr = 0;
998 char *query = "select value, server_type from node_tbl where name = ?";
1000 stmt = _query_prepare(mo_handler, query, strlen(query));
1002 _stmt_bind_text(mo_handler, stmt, 1, server_id_string);
1003 while (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
1004 sync_agent_dm_server_info_s *server_info = (sync_agent_dm_server_info_s *) calloc(1, sizeof(sync_agent_dm_server_info_s));
1005 if (server_info == NULL) {
1006 _DEBUG_ERROR("CALLOC failed !!!");
1007 return SYNC_AGENT_DM_MO_FAIL;
1009 server_info->server_id = _stmt_column_text(stmt, 0);
1010 server_info->server_type = _stmt_column_int(stmt, 1);
1012 if (current_ptr == NULL) {
1013 *head_ptr = server_info;
1014 current_ptr = *head_ptr;
1016 current_ptr->next = server_info;
1017 current_ptr = server_info;
1020 ret = _stmt_finalize(mo_handler, stmt);
1022 ret = SYNC_AGENT_DM_MO_FAIL;
1030 sync_agent_dm_mo_error_e dm_mo_get_root_path(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *mo_full_path, char **root_path)
1034 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1035 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1037 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1038 daci_stmt stmt = NULL;
1040 char *query = "select full_path from node_tbl where node_type = ? and mo_type = (select mo_type from node_tbl where full_path = ?)";
1042 stmt = _query_prepare(mo_handler, query, strlen(query));
1044 _stmt_bind_int(mo_handler, stmt, 1, SYNC_AGENT_DM_MO_NODE_FIRST);
1045 _stmt_bind_text(mo_handler, stmt, 2, mo_full_path);
1046 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
1047 *root_path = _stmt_column_text(stmt, 0);
1049 ret = _stmt_finalize(mo_handler, stmt);
1051 ret = SYNC_AGENT_DM_MO_FAIL;
1059 sync_agent_dm_mo_error_e dm_mo_add_framework_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id, sync_agent_dm_mo_framework_property_s * framework_property)
1063 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1064 retvm_if(framework_property == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_framework_property_s is NULL !!");
1066 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1067 daci_stmt stmt = NULL;
1070 query = "insert into framework_property_tbl " "(access_type, default_value, description, df_format, occurrence, occurrence_num, scope, df_title, df_type, df_type_value, node_id) " "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
1072 stmt = _query_prepare(mo_handler, query, strlen(query));
1075 ret = SYNC_AGENT_DM_MO_FAIL;
1079 /* _stmt_bind_int(mo_handler, stmt, 1, framework_property->id);*/
1080 _stmt_bind_int(mo_handler, stmt, 1, framework_property->accessType);
1081 _stmt_bind_text(mo_handler, stmt, 2, framework_property->defaultValue);
1082 _stmt_bind_text(mo_handler, stmt, 3, framework_property->description);
1083 _stmt_bind_int(mo_handler, stmt, 4, framework_property->dffFormat);
1084 _stmt_bind_int(mo_handler, stmt, 5, framework_property->occurrence);
1085 _stmt_bind_int(mo_handler, stmt, 6, framework_property->occurrence_num);
1086 _stmt_bind_int(mo_handler, stmt, 7, framework_property->scope);
1087 _stmt_bind_text(mo_handler, stmt, 8, framework_property->dfTitle);
1088 _stmt_bind_int(mo_handler, stmt, 9, framework_property->dfType);
1089 _stmt_bind_text(mo_handler, stmt, 10, framework_property->dfType_Value);
1090 _stmt_bind_int(mo_handler, stmt, 11, mo_node_id);
1092 ret = _stmt_step(mo_handler, stmt);
1094 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
1095 ret = SYNC_AGENT_DM_MO_FAIL;
1100 _stmt_finalize(mo_handler, stmt);
1107 sync_agent_dm_mo_error_e dm_mo_delete_framework_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id)
1111 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1113 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1114 daci_stmt stmt = NULL;
1117 query = "delete from framework_property_tbl where node_id = ?";
1119 stmt = _query_prepare(mo_handler, query, strlen(query));
1121 ret = SYNC_AGENT_DM_MO_FAIL;
1125 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
1126 ret = _stmt_step(mo_handler, stmt);
1131 _stmt_finalize(mo_handler, stmt);
1138 sync_agent_dm_mo_error_e dm_mo_update_framework_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id, sync_agent_dm_mo_framework_property_s * framework_property)
1142 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1143 retvm_if(framework_property == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_framework_property_s *framework_property is NULL !!");
1145 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1146 daci_stmt stmt = NULL;
1149 query = "update framework_property_tbl set access_type = ?, default_value = ?, description = ?, df_format = ?, occurrence = ?," "occurrence_num = ?, scope = ?, df_title = ?, df_type = ?, df_type_value = ? where node_id = ?";
1151 stmt = _query_prepare(mo_handler, query, strlen(query));
1153 ret = SYNC_AGENT_DM_MO_FAIL;
1156 _stmt_bind_int(mo_handler, stmt, 1, framework_property->accessType);
1157 _stmt_bind_text(mo_handler, stmt, 2, framework_property->defaultValue);
1158 _stmt_bind_text(mo_handler, stmt, 3, framework_property->description);
1159 _stmt_bind_int(mo_handler, stmt, 4, framework_property->dffFormat);
1160 _stmt_bind_int(mo_handler, stmt, 5, framework_property->occurrence);
1161 _stmt_bind_int(mo_handler, stmt, 6, framework_property->occurrence_num);
1162 _stmt_bind_int(mo_handler, stmt, 7, framework_property->scope);
1163 _stmt_bind_text(mo_handler, stmt, 8, framework_property->dfTitle);
1164 _stmt_bind_int(mo_handler, stmt, 9, framework_property->dfType);
1165 _stmt_bind_text(mo_handler, stmt, 10, framework_property->dfType_Value);
1166 _stmt_bind_int(mo_handler, stmt, 11, mo_node_id);
1168 ret = _stmt_step(mo_handler, stmt);
1169 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
1170 ret = SYNC_AGENT_DM_MO_FAIL;
1175 _stmt_finalize(mo_handler, stmt);
1182 sync_agent_dm_mo_error_e dm_mo_get_framework_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id, sync_agent_dm_mo_framework_property_s ** framework_property)
1186 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1188 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1189 daci_stmt stmt = NULL;
1190 char *query = "select * from framework_property_tbl where node_id = ?";
1191 sync_agent_dm_mo_framework_property_s *temp_framework_property = 0;
1193 stmt = _query_prepare(mo_handler, query, strlen(query));
1195 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
1197 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
1198 temp_framework_property = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_framework_property_s *, sizeof(sync_agent_dm_mo_framework_property_s), 1);
1199 /* temp_framework_property->framework_property_id = _stmt_column_int(stmt, 0);*/
1200 temp_framework_property->accessType = _stmt_column_int(stmt, 1);
1201 temp_framework_property->defaultValue = _stmt_column_text(stmt, 2);
1202 temp_framework_property->description = _stmt_column_text(stmt, 3);
1203 temp_framework_property->dffFormat = _stmt_column_int(stmt, 4);
1204 temp_framework_property->occurrence = _stmt_column_int(stmt, 5);
1205 temp_framework_property->occurrence_num = _stmt_column_int(stmt, 6);
1206 temp_framework_property->scope = _stmt_column_int(stmt, 7);
1207 temp_framework_property->dfTitle = _stmt_column_text(stmt, 8);
1208 temp_framework_property->dfType = _stmt_column_int(stmt, 9);
1209 temp_framework_property->dfType_Value = _stmt_column_text(stmt, 10);
1210 /* temp_framework_property->node_id = _stmt_column_text(stmt, 9);*/
1212 ret = _stmt_finalize(mo_handler, stmt);
1214 ret = SYNC_AGENT_DM_MO_FAIL;
1217 (*framework_property) = temp_framework_property;
1224 sync_agent_dm_mo_error_e dm_mo_delete_all_framework_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
1228 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1230 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1231 daci_stmt stmt = NULL;
1234 query = "delete from framework_property_tbl";
1236 stmt = _query_prepare(mo_handler, query, strlen(query));
1238 ret = SYNC_AGENT_DM_MO_FAIL;
1242 ret = _stmt_step(mo_handler, stmt);
1247 _stmt_finalize(mo_handler, stmt);
1254 sync_agent_dm_mo_error_e dm_mo_add_runtime_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id, sync_agent_dm_mo_runtime_property_s * runtime_property)
1258 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1259 retvm_if(runtime_property == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_runtime_property_s is NULL !!");
1261 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1262 daci_stmt stmt = NULL;
1265 query = "insert into runtime_property_tbl " "(acl, format, name, size, title, t_stamp, type, type_value, ver_no, node_id) " "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
1267 stmt = _query_prepare(mo_handler, query, strlen(query));
1269 ret = SYNC_AGENT_DM_MO_FAIL;
1273 _stmt_bind_text(mo_handler, stmt, 1, runtime_property->acl);
1274 _stmt_bind_int(mo_handler, stmt, 2, runtime_property->format);
1275 _stmt_bind_text(mo_handler, stmt, 3, runtime_property->name);
1276 _stmt_bind_text(mo_handler, stmt, 4, runtime_property->size);
1277 _stmt_bind_text(mo_handler, stmt, 5, runtime_property->title);
1278 _stmt_bind_text(mo_handler, stmt, 6, runtime_property->tStamp);
1279 _stmt_bind_int(mo_handler, stmt, 7, runtime_property->type);
1280 _stmt_bind_text(mo_handler, stmt, 8, runtime_property->type_value);
1281 _stmt_bind_text(mo_handler, stmt, 9, runtime_property->verNo);
1282 _stmt_bind_int(mo_handler, stmt, 10, mo_node_id);
1284 ret = _stmt_step(mo_handler, stmt);
1285 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
1286 ret = SYNC_AGENT_DM_MO_FAIL;
1291 _stmt_finalize(mo_handler, stmt);
1298 sync_agent_dm_mo_error_e dm_mo_delete_runtime_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id)
1302 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1304 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1305 daci_stmt stmt = NULL;
1308 query = "delete from runtime_property_tbl where node_id = ?";
1310 stmt = _query_prepare(mo_handler, query, strlen(query));
1312 ret = SYNC_AGENT_DM_MO_FAIL;
1316 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
1317 ret = _stmt_step(mo_handler, stmt);
1322 _stmt_finalize(mo_handler, stmt);
1329 sync_agent_dm_mo_error_e dm_mo_update_runtime_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id, sync_agent_dm_mo_runtime_property_s * runtime_property)
1333 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1334 retvm_if(runtime_property == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_runtime_property_s is NULL !!");
1336 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1337 daci_stmt stmt = NULL;
1340 query = "update runtime_property_tbl set acl = ?, format = ?, name = ?, size = ?, title = ?," "t_stamp = ?, type = ?, type_value = ?, ver_no = ? where node_id = ?";
1342 stmt = _query_prepare(mo_handler, query, strlen(query));
1344 ret = SYNC_AGENT_DM_MO_FAIL;
1347 _stmt_bind_text(mo_handler, stmt, 1, runtime_property->acl);
1348 _stmt_bind_int(mo_handler, stmt, 2, runtime_property->format);
1349 _stmt_bind_text(mo_handler, stmt, 3, runtime_property->name);
1350 _stmt_bind_text(mo_handler, stmt, 4, runtime_property->size);
1351 _stmt_bind_text(mo_handler, stmt, 5, runtime_property->title);
1352 _stmt_bind_text(mo_handler, stmt, 6, runtime_property->tStamp);
1353 _stmt_bind_int(mo_handler, stmt, 7, runtime_property->type);
1354 _stmt_bind_text(mo_handler, stmt, 8, runtime_property->type_value);
1355 _stmt_bind_text(mo_handler, stmt, 9, runtime_property->verNo);
1356 _stmt_bind_int(mo_handler, stmt, 10, mo_node_id);
1358 ret = _stmt_step(mo_handler, stmt);
1359 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
1360 ret = SYNC_AGENT_DM_MO_FAIL;
1365 _stmt_finalize(mo_handler, stmt);
1372 sync_agent_dm_mo_error_e dm_mo_get_runtime_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id, sync_agent_dm_mo_runtime_property_s ** runtime_property)
1376 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1378 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1379 daci_stmt stmt = NULL;
1380 char *query = "select * from runtime_property_tbl where node_id = ?";
1381 sync_agent_dm_mo_runtime_property_s *temp_runtime_property = 0;
1383 stmt = _query_prepare(mo_handler, query, strlen(query));
1385 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
1387 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
1388 temp_runtime_property = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_runtime_property_s *, sizeof(sync_agent_dm_mo_runtime_property_s), 1);
1389 /* temp_runtime_property->runtime_property_id = _stmt_column_int(stmt, 0);*/
1390 temp_runtime_property->acl = _stmt_column_text(stmt, 1);
1391 temp_runtime_property->format = _stmt_column_int(stmt, 2);
1392 temp_runtime_property->name = _stmt_column_text(stmt, 3);
1393 temp_runtime_property->size = _stmt_column_text(stmt, 4);
1394 temp_runtime_property->title = _stmt_column_text(stmt, 5);
1395 temp_runtime_property->tStamp = _stmt_column_text(stmt, 6);
1396 temp_runtime_property->type = _stmt_column_int(stmt, 7);
1397 temp_runtime_property->type_value = _stmt_column_text(stmt, 8);
1398 temp_runtime_property->verNo = _stmt_column_text(stmt, 9);
1399 /* temp_runtime_property->node_id = _stmt_column_text(stmt, 10);*/
1401 ret = _stmt_finalize(mo_handler, stmt);
1403 ret = SYNC_AGENT_DM_MO_FAIL;
1406 (*runtime_property) = temp_runtime_property;
1413 sync_agent_dm_mo_error_e dm_mo_delete_all_runtime_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
1417 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1419 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1420 daci_stmt stmt = NULL;
1423 query = "delete from runtime_property_tbl";
1425 stmt = _query_prepare(mo_handler, query, strlen(query));
1427 ret = SYNC_AGENT_DM_MO_FAIL;
1431 ret = _stmt_step(mo_handler, stmt);
1436 _stmt_finalize(mo_handler, stmt);
1443 int _busy_handler(void *pData, int count)
1447 _DEBUG_ERROR("_busy_handler %d called", count);
1449 //retvm_if(pData == NULL, 0, "pData is NULL !!");
1450 warn_if(pData == NULL, "pData is NULL !!");
1452 /* sleep time when SQLITE_LOCK */
1458 /* retry will be stopped if busy handler return 0 */
1459 return SYNC_AGENT_DA_RETRY_COUNT - count;
1462 sync_agent_dm_mo_error_e _query_exec(SYNC_AGENT_DA_MO_HANDLER * mo_handler, char *query, char *err_msg)
1466 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1467 retvm_if(query == NULL, SYNC_AGENT_DM_MO_FAIL, "query is NULL !!");
1469 char *queryMsg = NULL;
1472 ret = sqlite3_exec(mo_handler, query, 0, 0, &queryMsg);
1473 if (ret != SQLITE_OK) {
1474 _DEBUG_ERROR("%s(%d) : %s", err_msg, ret, queryMsg);
1476 if (queryMsg != NULL)
1477 sqlite3_free(queryMsg);
1480 if (ret == SQLITE_BUSY)
1481 return SYNC_AGENT_DM_MO_FAIL;
1484 return SYNC_AGENT_DM_MO_FAIL;
1489 return SYNC_AGENT_DM_MO_SUCCESS;
1492 daci_stmt _query_prepare(SYNC_AGENT_DA_MO_HANDLER * mo_handler, char *query, int size)
1496 retvm_if(mo_handler == NULL, NULL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1497 retvm_if(query == NULL, NULL, "query is NULL !!");
1500 daci_stmt stmt = NULL;
1502 ret = sqlite3_prepare_v2(mo_handler, query, size, &stmt, 0);
1503 if (ret != SQLITE_OK)
1504 _DEBUG_ERROR("sqlite3_query_prepare failed(%d) : %s ", ret, sqlite3_errmsg(mo_handler));
1511 sync_agent_da_return_e _stmt_bind_text(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index, const char *value)
1515 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1519 if (value != NULL) {
1520 ret = sqlite3_bind_text(stmt, index, value, strlen(value), SQLITE_STATIC);
1522 ret = __stmt_bind_null(mo_handler, stmt, index);
1523 if (ret == SYNC_AGENT_DA_SUCCESS)
1527 if (ret != SQLITE_OK) {
1528 _DEBUG_ERROR("sqlite3_stmt_bind_text failed(%d) : %s ", ret, sqlite3_errmsg(mo_handler));
1529 return SYNC_AGENT_DA_ERR_QUERY_FAILED;
1534 return SYNC_AGENT_DA_SUCCESS;
1537 sync_agent_dm_mo_error_e _stmt_bind_int(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index, const int value)
1541 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1545 ret = sqlite3_bind_int(stmt, index, value);
1546 if (ret != SQLITE_OK) {
1547 _DEBUG_ERROR("sqlite3_stmt_bind_int failed(%d) : %s \n", ret, sqlite3_errmsg(mo_handler));
1548 return SYNC_AGENT_DM_MO_FAIL;
1553 return SYNC_AGENT_DM_MO_SUCCESS;
1556 sync_agent_dm_mo_error_e __stmt_bind_null(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index)
1560 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1564 ret = sqlite3_bind_null(stmt, index);
1565 if (ret != SQLITE_OK) {
1566 _DEBUG_ERROR("sqlite3_stmt_bind_null failed(%d) : %s", ret, sqlite3_errmsg(mo_handler));
1567 return SYNC_AGENT_DM_MO_FAIL;
1572 return SYNC_AGENT_DM_MO_SUCCESS;
1575 sync_agent_da_return_e _stmt_step(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt)
1579 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1583 ret = sqlite3_step(stmt);
1585 if (ret == SQLITE_ROW)
1586 return SYNC_AGENT_DA_ERR_MORE_DATA;
1588 if (ret != SQLITE_DONE) {
1589 _DEBUG_ERROR("sqlite3_stmt_step failed(%d) : %s", ret, sqlite3_errmsg(mo_handler));
1591 /* if (ret == SQLITE_BUSY)
1592 return SYNC_AGENT_DM_MO_FAIL;*/
1594 return SYNC_AGENT_DM_MO_FAIL;
1599 return SYNC_AGENT_DM_MO_SUCCESS;
1602 sync_agent_dm_mo_error_e _stmt_finalize(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt)
1606 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1610 if (sqlite3_finalize(stmt) != SQLITE_OK) {
1611 _DEBUG_ERROR("sqlite3_stmt_finalize failed(%d) : %s", ret, sqlite3_errmsg(mo_handler));
1612 return SYNC_AGENT_DM_MO_FAIL;
1617 return SYNC_AGENT_DM_MO_SUCCESS;
1620 char *_stmt_column_text(daci_stmt stmt, int index)
1624 retvm_if(stmt == NULL, NULL, "daci_stmt is NULL !!");
1627 temp = (char *)sqlite3_column_text(stmt, index);
1631 return SYNC_AGENT_DA_STRDUP(temp);
1634 int _stmt_column_int(daci_stmt stmt, int index)
1640 return (int)sqlite3_column_int(stmt, index);
1643 sync_agent_dm_mo_error_e _get_table(SYNC_AGENT_DA_MO_HANDLER * mo_handler, char *query, char ***result, int *row_count, int *col_count)
1647 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1650 char *err_msg = NULL;
1652 ret = sqlite3_get_table(mo_handler, query, result, row_count, col_count, &err_msg);
1654 if (ret != SQLITE_OK) {
1655 _DEBUG_ERROR("sqlite3_get_table failed(%d) : %s", ret, err_msg);
1657 _free_table(*result);
1659 if (err_msg != NULL)
1660 sqlite3_free(err_msg);
1662 return SYNC_AGENT_DM_MO_FAIL;
1667 return SYNC_AGENT_DM_MO_SUCCESS;
1670 void _free_table(char **result)
1674 if (result != NULL) {
1675 sqlite3_free_table(result);
1682 static int _last_insert_id(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
1688 return sqlite3_last_insert_rowid(mo_handler);
1691 int _exist_table(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *table_name)
1695 daci_stmt stmt = NULL;
1696 int table_count = 0;
1697 char *query = "select count(*) from sqlite_master where tbl_name= ?";
1699 stmt = _query_prepare(mo_handler, query, strlen(query));
1700 if ((stmt != NULL) && (_stmt_bind_text(mo_handler, stmt, 1, table_name) == SYNC_AGENT_DA_ERR_MORE_DATA)) {
1702 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA)
1703 table_count = _stmt_column_int(stmt, 0);
1705 _stmt_finalize(mo_handler, stmt);
1707 if (table_count > 0) {
1718 static char *_extract_dmacc_name(const char *mo_full_path)
1722 char *dmacc_name = NULL;
1725 const char *cursor = mo_full_path;
1726 const char *start_point = NULL;
1727 while (cursor != NULL) {
1728 cursor = strchr(cursor, '/');
1729 if (cursor == NULL) {
1736 start_point = cursor;
1737 } else if (cnt == 3) {
1738 int len = cursor - start_point + 2;
1740 dmacc_name = (char *)calloc(len, sizeof(char));
1741 if (dmacc_name == NULL) {
1742 _DEBUG_ERROR("CALLOC failed !!!");
1745 strncpy(dmacc_name, start_point, len - 1);