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 */
52 "create table node_tbl "
53 "( " "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, "
54 "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) " ");",
56 "create table node_tbl "
57 "( " "node_id integer primary key autoincrement, " "name varchar(100) not null, " "value varchar(500) default null, " "parent_node_id integer default null, " "full_path varchar(200) not null, " "node_type integer not null, "
58 "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) " ");",
60 /* 2. create framework_property_tbl */
61 "create table framework_property_tbl "
63 "framework_property_id integer primary key autoincrement, "
64 "access_type integer default null, "
65 "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, "
66 "df_title varchar(100) default null, " "df_type integer default null, " "df_type_value varchar(20) default null, " "node_id integer not null unique, "
67 "constraint framework_property_tbl_node_id_fk foreign key(node_id) references node_tbl(node_id) " ");",
69 /* 3. create runtime_property_tbl */
70 "create table runtime_property_tbl "
72 "runtime_property_id integer primary key autoincrement, "
73 "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, "
74 "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) " ");",
78 sync_agent_dm_mo_error_e dm_mo_begin_transaction(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
82 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
84 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
86 ret = _query_exec(mo_handler, "begin immediate", "begin_transaction failed");
88 /* if (ret == SYNC_AGENT_DA_ERR_QUERY_FAILED)
89 ret = SYNC_AGENT_DA_ERR_TRANSACTION_FAILED;*/
96 sync_agent_dm_mo_error_e dm_mo_end_transaction(SYNC_AGENT_DA_MO_HANDLER * mo_handler, sync_agent_da_transaction_e transaction)
100 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
102 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
104 char *err_msg = NULL;
106 if (transaction == SYNC_AGENT_DA_TRANSACTION_COMMIT) {
107 query = "commit transaction";
108 err_msg = "commit_transaction failed";
109 } else if (transaction == SYNC_AGENT_DA_TRANSACTION_ROLLBACK) {
110 query = "rollback transaction";
111 err_msg = "rollback_transaction failed";
114 ret = _query_exec(mo_handler, query, err_msg);
115 if (ret == SYNC_AGENT_DM_MO_FAIL) {
116 if (transaction == SYNC_AGENT_DA_TRANSACTION_COMMIT) {
117 query = "rollback transaction";
118 err_msg = "rollback_transaction failed";
119 ret = _query_exec(mo_handler, query, err_msg);
120 if (ret == SYNC_AGENT_DM_MO_SUCCESS)
121 _DEBUG_INFO("rollback_transaction success");
123 ret = SYNC_AGENT_DM_MO_FAIL;
131 sync_agent_dm_mo_error_e mo_open_agent(SYNC_AGENT_DA_MO_HANDLER ** mo_handler, char *database_path)
135 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
138 char *err_msg = NULL;
140 if (*mo_handler == NULL) {
143 /* ret = db_util_open(DACI_FILE_PATH, &(*t_daci_handler), 0); */
145 ret = sqlite3_open(database_path, mo_handler);
146 if (ret != SQLITE_OK)
149 /* register busy handler */
150 ret = sqlite3_busy_handler(*mo_handler, _busy_handler, 0);
151 if (ret != SQLITE_OK) {
152 _DEBUG_INFO("fail to register busy handler", err_msg);
156 /* enable persist journal mode */
157 ret = sqlite3_exec(*mo_handler, "PRAGMA journal_mode = PERSIST", 0, 0, &err_msg);
158 if (ret != SQLITE_OK) {
159 _DEBUG_INFO("fail to change journal mode: %s", err_msg);
163 _DEBUG_INFO("mo_db_open success");
166 _DEBUG_INFO("mo_db_already opened");
171 return SYNC_AGENT_DM_MO_SUCCESS;
175 _DEBUG_ERROR("agent_db_open failed(%d) : %s", ret, sqlite3_errmsg(*mo_handler));
178 sqlite3_free(err_msg);
180 sqlite3_close(*mo_handler);
183 return SYNC_AGENT_DM_MO_FAIL;
186 sync_agent_dm_mo_error_e mo_close_agent(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
190 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
193 ret = sqlite3_close(mo_handler);
196 if (ret != SQLITE_OK) {
197 _DEBUG_ERROR("mo_db_close failed(%d) : %s", ret, sqlite3_errmsg(mo_handler));
198 return SYNC_AGENT_DM_MO_FAIL;
201 _DEBUG_INFO("mo_db_close success");
205 return SYNC_AGENT_DM_MO_SUCCESS;
208 sync_agent_dm_mo_error_e dm_mo_create_mo_table(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
212 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
214 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
216 if (mo_handler == NULL) {
217 _DEBUG_INFO("[%s] sync_agent_dm_mo_error_e !\n", __func__);
218 return SYNC_AGENT_DM_MO_FAIL;
221 if ((dm_mo_begin_transaction(mo_handler) != SYNC_AGENT_DM_MO_SUCCESS)) {
222 _DEBUG_ERROR("mo_db_default_tbl_create failed");
223 return SYNC_AGENT_DM_MO_FAIL;
226 /* 1. create node_tbl */
227 if (_exist_table(mo_handler, "node_tbl") == 0) {
228 ret = _query_exec(mo_handler, __create_table[0], "node_tbl_create failed");
229 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
233 /* 2. create framework_property_tbl */
234 if (_exist_table(mo_handler, "framework_property_tbl") == 0) {
235 ret = _query_exec(mo_handler, __create_table[1], "framework_property_tbl_create failed");
236 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
240 /* 3. create runtime_property_tbl */
241 if (_exist_table(mo_handler, "runtime_property_tbl") == 0) {
242 ret = _query_exec(mo_handler, __create_table[2], "runtime_property_tbl_create failed");
243 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
249 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
250 dm_mo_end_transaction(mo_handler, SYNC_AGENT_DA_TRANSACTION_ROLLBACK);
251 ret = SYNC_AGENT_DM_MO_FAIL;
253 ret = dm_mo_end_transaction(mo_handler, SYNC_AGENT_DA_TRANSACTION_COMMIT);
261 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)
265 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
266 retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
268 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
269 daci_stmt stmt = NULL;
272 query = "insert into node_tbl (name, value, parent_node_id, full_path, node_type, mo_type, server_type) values (?, ?, ?, ?, ?, ?, ?)";
274 stmt = _query_prepare(mo_handler, query, strlen(query));
276 ret = SYNC_AGENT_DM_MO_FAIL;
280 /* _stmt_bind_int(mo_handler, stmt, 1, mo_node->id);*/
281 _stmt_bind_text(mo_handler, stmt, 1, mo_node->name);
282 _stmt_bind_text(mo_handler, stmt, 2, mo_node->value);
283 _stmt_bind_int(mo_handler, stmt, 3, mo_node->parent_id);
284 _stmt_bind_text(mo_handler, stmt, 4, mo_node->full_path);
285 _stmt_bind_int(mo_handler, stmt, 5, mo_node->type);
286 _stmt_bind_int(mo_handler, stmt, 6, mo_type);
287 _stmt_bind_int(mo_handler, stmt, 7, mo_node->server_type);
289 ret = _stmt_step(mo_handler, stmt);
290 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
291 ret = SYNC_AGENT_DM_MO_FAIL;
296 _stmt_finalize(mo_handler, stmt);
298 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
301 mo_node->id = _last_insert_id(mo_handler);
309 sync_agent_dm_mo_error_e dm_mo_delete_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id)
313 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
315 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
316 daci_stmt stmt = NULL;
319 query = "delete from node_tbl where node_id = ?";
321 stmt = _query_prepare(mo_handler, query, strlen(query));
323 ret = SYNC_AGENT_DM_MO_FAIL;
327 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
328 ret = _stmt_step(mo_handler, stmt);
333 _stmt_finalize(mo_handler, stmt);
340 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)
344 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
345 retvm_if(mo_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
347 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
348 daci_stmt stmt = NULL;
351 query = "update node_tbl set value = ? where full_path = ? and mo_type = ?";
353 stmt = _query_prepare(mo_handler, query, strlen(query));
355 ret = SYNC_AGENT_DM_MO_FAIL;
359 _stmt_bind_text(mo_handler, stmt, 1, mo_node->value);
360 _stmt_bind_text(mo_handler, stmt, 2, path);
361 _stmt_bind_int(mo_handler, stmt, 3, mo_type);
363 ret = _stmt_step(mo_handler, stmt);
367 _stmt_finalize(mo_handler, stmt);
374 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)
378 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
380 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
381 daci_stmt stmt = NULL;
382 char *query = "select * from node_tbl where full_path = ?";
383 sync_agent_dm_mo_node_s *temp_mo_node = NULL;
385 stmt = _query_prepare(mo_handler, query, strlen(query));
388 _stmt_bind_text(mo_handler, stmt, 1, path);
389 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
390 temp_mo_node = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_node_s *, sizeof(sync_agent_dm_mo_node_s), 1);
391 temp_mo_node->id = _stmt_column_int(stmt, 0);
392 temp_mo_node->name = _stmt_column_text(stmt, 1);
393 temp_mo_node->value = _stmt_column_text(stmt, 2);
394 temp_mo_node->parent_id = _stmt_column_int(stmt, 3);
395 temp_mo_node->full_path = _stmt_column_text(stmt, 4);
396 temp_mo_node->type = _stmt_column_int(stmt, 5);
397 temp_mo_node->mo_type = _stmt_column_int(stmt, 6);
398 temp_mo_node->server_type = _stmt_column_int(stmt, 7);
399 temp_mo_node->runtime_property = 0;
400 temp_mo_node->framework_property = 0;
402 ret = SYNC_AGENT_DM_MO_FAIL;
404 ret = _stmt_finalize(mo_handler, stmt);
406 ret = SYNC_AGENT_DM_MO_FAIL;
409 (*mo_node) = temp_mo_node;
416 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)
420 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
422 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
423 daci_stmt stmt = NULL;
424 char *query = "select * from node_tbl where full_path = ?";
425 sync_agent_dm_mo_node_s *current_ptr = NULL;
427 stmt = _query_prepare(mo_handler, query, strlen(query));
429 _stmt_bind_text(mo_handler, stmt, 1, path);
431 while (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
432 _DEBUG_INFO("nodes called!!!");
433 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);
434 if (temp_mo_node == NULL) {
435 _DEBUG_ERROR("CALLOC failed !!!");
436 return SYNC_AGENT_DM_MO_FAIL;
438 temp_mo_node->id = _stmt_column_int(stmt, 0);
439 temp_mo_node->name = _stmt_column_text(stmt, 1);
440 temp_mo_node->value = _stmt_column_text(stmt, 2);
441 temp_mo_node->parent_id = _stmt_column_int(stmt, 3);
442 temp_mo_node->full_path = _stmt_column_text(stmt, 4);
443 temp_mo_node->type = _stmt_column_int(stmt, 5);
444 temp_mo_node->mo_type = _stmt_column_int(stmt, 6);
445 temp_mo_node->server_type = _stmt_column_int(stmt, 7);
446 temp_mo_node->runtime_property = 0;
447 temp_mo_node->framework_property = 0;
448 if (current_ptr == NULL) {
449 _DEBUG_INFO("nodes first node!!!");
450 (*mo_node) = temp_mo_node;
451 current_ptr = (*mo_node);
453 _DEBUG_INFO("nodes next node!!!");
454 current_ptr->next_node = temp_mo_node;
455 current_ptr = temp_mo_node;
458 ret = _stmt_finalize(mo_handler, stmt);
460 ret = SYNC_AGENT_DM_MO_FAIL;
468 sync_agent_dm_mo_error_e dm_mo_is_exist_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *path)
472 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
473 retvm_if(path == NULL, SYNC_AGENT_DM_MO_FAIL, "path is NULL !!");
475 _DEBUG_INFO("[%s] Start path : %s\n", __func__, path);
477 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
478 daci_stmt stmt = NULL;
480 char query[1024] = { 0, };
482 snprintf(query, sizeof(query), "select count(*) from node_tbl where full_path = \'%s\' ", path);
484 stmt = _query_prepare(mo_handler, query, strlen(query));
486 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA)
487 data_count = _stmt_column_int(stmt, 0);
489 _stmt_finalize(mo_handler, stmt);
492 if (data_count == 0) {
493 ret = SYNC_AGENT_DM_MO_NOT_EXIST_NODE;
495 ret = SYNC_AGENT_DM_MO_EXIST_NODE;
503 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)
507 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
508 retvm_if(path == NULL, SYNC_AGENT_DM_MO_FAIL, "path is NULL !!");
510 _DEBUG_INFO("[%s] Start ! mopath : %s , mo type : %d\n", __func__, path, mo_type);
512 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_FAIL; // SYNC_AGENT_DM_MO_SUCCESS;
513 sync_agent_dm_mo_node_s *temp_mo_node = NULL;
514 char **result = NULL;
519 char query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = { 0, };
521 if (!strcmp(path, ".")) {
522 snprintf(query, sizeof(query), "select * from node_tbl where parent_node_id in " "(select node_id from node_tbl where full_path = \'%s\')", path);
523 ret = _get_table(mo_handler, query, &result, &row_count, &col_count);
524 if (result == NULL) {
525 _DEBUG_ERROR("result is NULL!!");
526 ret = SYNC_AGENT_DM_MO_FAIL;
530 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);
531 ret = _get_table(mo_handler, query, &result, &row_count, &col_count);
532 if (result == NULL) {
533 _DEBUG_ERROR("result is NULL!!");
534 ret = SYNC_AGENT_DM_MO_FAIL;
539 if ((ret == SYNC_AGENT_DM_MO_SUCCESS) && (row_count != 0)) {
541 temp_mo_node = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_node_s *, sizeof(sync_agent_dm_mo_node_s), row_count);
542 if (temp_mo_node == NULL) {
543 _DEBUG_ERROR("memory_allocation failed");
544 ret = SYNC_AGENT_DM_MO_FAIL;
548 for (i = 0; i < row_count; i++) {
549 temp_mo_node[i].id = SYNC_AGENT_DA_ATOI(result[index]);
551 temp_mo_node[i].name = SYNC_AGENT_DA_STRDUP(result[index]);
553 temp_mo_node[i].value = SYNC_AGENT_DA_STRDUP(result[index]);
555 temp_mo_node[i].parent_id = SYNC_AGENT_DA_ATOI(result[index]);
557 temp_mo_node[i].full_path = SYNC_AGENT_DA_STRDUP(result[index]);
559 temp_mo_node[i].type = SYNC_AGENT_DA_ATOI(result[index]);
561 temp_mo_node[i].mo_type = SYNC_AGENT_DA_ATOI(result[index]);
563 temp_mo_node[i].server_type = SYNC_AGENT_DA_ATOI(result[index]);
567 ret = SYNC_AGENT_DM_MO_SUCCESS;
571 (*mo_node) = temp_mo_node;
575 ret = SYNC_AGENT_DM_MO_FAIL;
583 //(*mo_node) = temp_mo_node;
590 sync_agent_dm_mo_error_e dm_mo_delete_all_node(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
594 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
596 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
597 daci_stmt stmt = NULL;
600 query = "delete from node_tbl";
602 stmt = _query_prepare(mo_handler, query, strlen(query));
604 ret = SYNC_AGENT_DM_MO_FAIL;
607 ret = _stmt_step(mo_handler, stmt);
612 _stmt_finalize(mo_handler, stmt);
619 sync_agent_dm_mo_type_e dm_mo_get_mo_type(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *mo_full_path)
623 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_TYPE_NO_TYPE, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
624 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_TYPE_NO_TYPE, "mo_full_path is NULL !!");
626 sync_agent_dm_mo_type_e mo_type = SYNC_AGENT_DM_MO_TYPE_NO_TYPE;
627 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
628 daci_stmt stmt = NULL;
629 char *query = "select mo_type from node_tbl where full_path = ?";
631 stmt = _query_prepare(mo_handler, query, strlen(query));
634 _stmt_bind_text(mo_handler, stmt, 1, mo_full_path);
635 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
636 mo_type = _stmt_column_int(stmt, 0);
638 ret = _stmt_finalize(mo_handler, stmt);
640 ret = SYNC_AGENT_DM_MO_FAIL;
648 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)
652 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
654 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
655 daci_stmt stmt = NULL;
656 char *query = "select * from node_tbl where node_id = ?";
657 sync_agent_dm_mo_node_s *temp_mo_node = NULL;
659 stmt = _query_prepare(mo_handler, query, strlen(query));
662 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
663 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
664 temp_mo_node = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_node_s *, sizeof(sync_agent_dm_mo_node_s), 1);
665 temp_mo_node->id = _stmt_column_int(stmt, 0);
666 temp_mo_node->name = _stmt_column_text(stmt, 1);
667 temp_mo_node->value = _stmt_column_text(stmt, 2);
668 temp_mo_node->parent_id = _stmt_column_int(stmt, 3);
669 temp_mo_node->full_path = _stmt_column_text(stmt, 4);
670 temp_mo_node->type = _stmt_column_int(stmt, 5);
671 temp_mo_node->mo_type = _stmt_column_int(stmt, 6);
672 temp_mo_node->server_type = _stmt_column_int(stmt, 7);
673 temp_mo_node->runtime_property = 0;
674 temp_mo_node->framework_property = 0;
676 ret = _stmt_finalize(mo_handler, stmt);
678 ret = SYNC_AGENT_DM_MO_FAIL;
681 (*mo_node) = temp_mo_node;
688 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)
692 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
693 retvm_if(server_id == NULL, SYNC_AGENT_DM_MO_FAIL, "server id is NULL !!");
694 retvm_if(server_id_string == NULL, SYNC_AGENT_DM_MO_FAIL, "server id string is NULL !!");
695 retvm_if(acc_type_string == NULL, SYNC_AGENT_DM_MO_FAIL, "acc type string is NULL !!");
697 _DEBUG_INFO("get acc type string : %s ", acc_type_string);
698 _DEBUG_INFO("get acc server id string : %s ", server_id_string);
699 _DEBUG_INFO("get acc server id : %s ", server_id);
701 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
702 daci_stmt stmt = NULL;
703 char *query = "select full_path from node_tbl where name = ? and value = ? and mo_type = ?";
704 char *full_path = NULL;
706 stmt = _query_prepare(mo_handler, query, strlen(query));
709 _stmt_bind_text(mo_handler, stmt, 1, server_id_string);
710 _stmt_bind_text(mo_handler, stmt, 2, server_id);
711 _stmt_bind_int(mo_handler, stmt, 3, SYNC_AGENT_DM_MO_TYPE_DMACC);
712 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
713 full_path = _stmt_column_text(stmt, 0);
715 ret = _stmt_finalize(mo_handler, stmt);
717 ret = SYNC_AGENT_DM_MO_FAIL;
720 _DEBUG_INFO("full_path : %s", full_path);
721 if (full_path == NULL) {
722 return SYNC_AGENT_DM_MO_FAIL;
725 * Parsing full_path and extract dmacc name
727 char *dmacc_name = _extract_dmacc_name(full_path);
728 _DEBUG_INFO("dmacc_name : %s", dmacc_name);
730 if (dmacc_name == NULL) {
731 return SYNC_AGENT_DM_MO_FAIL;
734 *acc_info = (sync_agent_dm_acc_info_s *) calloc(1, sizeof(sync_agent_dm_acc_info_s));
735 if (*acc_info == NULL) {
736 _DEBUG_ERROR("CALLOC failed !!!");
737 return SYNC_AGENT_DM_MO_FAIL;
743 char query01[2048] = { 0, };
744 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);
746 stmt = _query_prepare(mo_handler, query01, strlen(query01));
748 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
749 (*acc_info)->auth_name = _stmt_column_text(stmt, 0);
751 ret = _stmt_finalize(mo_handler, stmt);
753 ret = SYNC_AGENT_DM_MO_FAIL;
759 char query02[2048] = { 0, };
760 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);
762 stmt = _query_prepare(mo_handler, query02, strlen(query02));
764 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
765 (*acc_info)->auth_secret = _stmt_column_text(stmt, 0);
767 ret = _stmt_finalize(mo_handler, stmt);
769 ret = SYNC_AGENT_DM_MO_FAIL;
775 char query03[2048] = { 0, };
776 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);
778 stmt = _query_prepare(mo_handler, query03, strlen(query03));
780 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
781 (*acc_info)->auth_level = _stmt_column_text(stmt, 0);
783 ret = _stmt_finalize(mo_handler, stmt);
785 ret = SYNC_AGENT_DM_MO_FAIL;
791 char query04[2048] = { 0, };
792 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);
794 stmt = _query_prepare(mo_handler, query04, strlen(query04));
796 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
797 (*acc_info)->auth_data = _stmt_column_text(stmt, 0);
799 ret = _stmt_finalize(mo_handler, stmt);
801 ret = SYNC_AGENT_DM_MO_FAIL;
807 char query05[2048] = { 0, };
808 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);
810 stmt = _query_prepare(mo_handler, query05, strlen(query05));
812 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
813 (*acc_info)->auth_type = _stmt_column_text(stmt, 0);
815 ret = _stmt_finalize(mo_handler, stmt);
817 ret = SYNC_AGENT_DM_MO_FAIL;
823 char query06[2048] = { 0, };
824 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);
826 stmt = _query_prepare(mo_handler, query06, strlen(query06));
828 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
829 (*acc_info)->addr = _stmt_column_text(stmt, 0);
831 ret = _stmt_finalize(mo_handler, stmt);
833 ret = SYNC_AGENT_DM_MO_FAIL;
836 if (dmacc_name != NULL) {
840 _DEBUG_INFO("[%s] End !\n", __func__);
847 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)
851 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
852 retvm_if(server_id == NULL, SYNC_AGENT_DM_MO_FAIL, "server id is NULL !!");
853 retvm_if(server_id_string == NULL, SYNC_AGENT_DM_MO_FAIL, "server id string is NULL !!");
854 retvm_if(acc_type_string == NULL, SYNC_AGENT_DM_MO_FAIL, "acc type string is NULL !!");
855 retvm_if(acc_info == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_acc_info_s is NULL !!");
857 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
859 daci_stmt stmt = NULL;
860 char *query = "select full_path from node_tbl where name = ? and value = ? and mo_type = ?";
861 char *full_path = NULL;
863 stmt = _query_prepare(mo_handler, query, strlen(query));
866 _stmt_bind_text(mo_handler, stmt, 1, server_id_string);
867 _stmt_bind_text(mo_handler, stmt, 2, server_id);
868 _stmt_bind_int(mo_handler, stmt, 3, SYNC_AGENT_DM_MO_TYPE_DMACC);
869 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
870 full_path = _stmt_column_text(stmt, 0);
872 ret = _stmt_finalize(mo_handler, stmt);
874 ret = SYNC_AGENT_DM_MO_FAIL;
877 _DEBUG_INFO("full_path : %s", full_path);
880 * Parsing full_path and extract dmacc name
882 char *dmacc_name = _extract_dmacc_name(full_path);
883 _DEBUG_INFO("dmacc_name : %s", dmacc_name);
885 if (dmacc_name == NULL) {
886 return SYNC_AGENT_DM_MO_FAIL;
892 char query01[2048] = { 0, };
893 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,
896 stmt = _query_prepare(mo_handler, query01, strlen(query01));
898 ret = _stmt_step(mo_handler, stmt);
900 ret = _stmt_finalize(mo_handler, stmt);
902 ret = SYNC_AGENT_DM_MO_FAIL;
908 char query02[2048] = { 0, };
909 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,
912 stmt = _query_prepare(mo_handler, query02, strlen(query02));
914 ret = _stmt_step(mo_handler, stmt);
916 ret = _stmt_finalize(mo_handler, stmt);
918 ret = SYNC_AGENT_DM_MO_FAIL;
924 char query03[2048] = { 0, };
925 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,
928 stmt = _query_prepare(mo_handler, query03, strlen(query03));
930 ret = _stmt_step(mo_handler, stmt);
932 ret = _stmt_finalize(mo_handler, stmt);
934 ret = SYNC_AGENT_DM_MO_FAIL;
940 char query04[2048] = { 0, };
941 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,
944 stmt = _query_prepare(mo_handler, query04, strlen(query04));
946 ret = _stmt_step(mo_handler, stmt);
948 ret = _stmt_finalize(mo_handler, stmt);
950 ret = SYNC_AGENT_DM_MO_FAIL;
956 char query05[2048] = { 0, };
957 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,
960 stmt = _query_prepare(mo_handler, query05, strlen(query05));
962 ret = _stmt_step(mo_handler, stmt);
964 ret = _stmt_finalize(mo_handler, stmt);
966 ret = SYNC_AGENT_DM_MO_FAIL;
972 char query06[2048] = { 0, };
973 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);
975 stmt = _query_prepare(mo_handler, query06, strlen(query06));
977 ret = _stmt_step(mo_handler, stmt);
979 ret = _stmt_finalize(mo_handler, stmt);
981 ret = SYNC_AGENT_DM_MO_FAIL;
984 if (dmacc_name != NULL) {
993 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)
997 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
998 retvm_if(server_id_string == NULL, SYNC_AGENT_DM_MO_FAIL, "server id string is NULL !!");
1000 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1001 sync_agent_dm_server_info_s *current_ptr = 0;
1003 char *query = "select value, server_type from node_tbl where name = ?";
1005 stmt = _query_prepare(mo_handler, query, strlen(query));
1007 _stmt_bind_text(mo_handler, stmt, 1, server_id_string);
1008 while (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
1009 sync_agent_dm_server_info_s *server_info = (sync_agent_dm_server_info_s *) calloc(1, sizeof(sync_agent_dm_server_info_s));
1010 if (server_info == NULL) {
1011 _DEBUG_ERROR("CALLOC failed !!!");
1012 return SYNC_AGENT_DM_MO_FAIL;
1014 server_info->server_id = _stmt_column_text(stmt, 0);
1015 server_info->server_type = _stmt_column_int(stmt, 1);
1017 if (current_ptr == NULL) {
1018 *head_ptr = server_info;
1019 current_ptr = *head_ptr;
1021 current_ptr->next = server_info;
1022 current_ptr = server_info;
1025 ret = _stmt_finalize(mo_handler, stmt);
1027 ret = SYNC_AGENT_DM_MO_FAIL;
1035 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)
1039 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1040 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
1042 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1043 daci_stmt stmt = NULL;
1045 char *query = "select full_path from node_tbl where node_type = ? and mo_type = (select mo_type from node_tbl where full_path = ?)";
1047 stmt = _query_prepare(mo_handler, query, strlen(query));
1049 _stmt_bind_int(mo_handler, stmt, 1, SYNC_AGENT_DM_MO_NODE_FIRST);
1050 _stmt_bind_text(mo_handler, stmt, 2, mo_full_path);
1051 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
1052 *root_path = _stmt_column_text(stmt, 0);
1054 ret = _stmt_finalize(mo_handler, stmt);
1056 ret = SYNC_AGENT_DM_MO_FAIL;
1064 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)
1068 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1069 retvm_if(framework_property == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_framework_property_s is NULL !!");
1071 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1072 daci_stmt stmt = NULL;
1075 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
1077 stmt = _query_prepare(mo_handler, query, strlen(query));
1080 ret = SYNC_AGENT_DM_MO_FAIL;
1084 /* _stmt_bind_int(mo_handler, stmt, 1, framework_property->id);*/
1085 _stmt_bind_int(mo_handler, stmt, 1, framework_property->accessType);
1086 _stmt_bind_text(mo_handler, stmt, 2, framework_property->defaultValue);
1087 _stmt_bind_text(mo_handler, stmt, 3, framework_property->description);
1088 _stmt_bind_int(mo_handler, stmt, 4, framework_property->dffFormat);
1089 _stmt_bind_int(mo_handler, stmt, 5, framework_property->occurrence);
1090 _stmt_bind_int(mo_handler, stmt, 6, framework_property->occurrence_num);
1091 _stmt_bind_int(mo_handler, stmt, 7, framework_property->scope);
1092 _stmt_bind_text(mo_handler, stmt, 8, framework_property->dfTitle);
1093 _stmt_bind_int(mo_handler, stmt, 9, framework_property->dfType);
1094 _stmt_bind_text(mo_handler, stmt, 10, framework_property->dfType_Value);
1095 _stmt_bind_int(mo_handler, stmt, 11, mo_node_id);
1097 ret = _stmt_step(mo_handler, stmt);
1099 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
1100 ret = SYNC_AGENT_DM_MO_FAIL;
1105 _stmt_finalize(mo_handler, stmt);
1112 sync_agent_dm_mo_error_e dm_mo_delete_framework_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id)
1116 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1118 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1119 daci_stmt stmt = NULL;
1122 query = "delete from framework_property_tbl where node_id = ?";
1124 stmt = _query_prepare(mo_handler, query, strlen(query));
1126 ret = SYNC_AGENT_DM_MO_FAIL;
1130 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
1131 ret = _stmt_step(mo_handler, stmt);
1136 _stmt_finalize(mo_handler, stmt);
1143 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)
1147 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1148 retvm_if(framework_property == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_framework_property_s *framework_property is NULL !!");
1150 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1151 daci_stmt stmt = NULL;
1154 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 = ?";
1156 stmt = _query_prepare(mo_handler, query, strlen(query));
1158 ret = SYNC_AGENT_DM_MO_FAIL;
1161 _stmt_bind_int(mo_handler, stmt, 1, framework_property->accessType);
1162 _stmt_bind_text(mo_handler, stmt, 2, framework_property->defaultValue);
1163 _stmt_bind_text(mo_handler, stmt, 3, framework_property->description);
1164 _stmt_bind_int(mo_handler, stmt, 4, framework_property->dffFormat);
1165 _stmt_bind_int(mo_handler, stmt, 5, framework_property->occurrence);
1166 _stmt_bind_int(mo_handler, stmt, 6, framework_property->occurrence_num);
1167 _stmt_bind_int(mo_handler, stmt, 7, framework_property->scope);
1168 _stmt_bind_text(mo_handler, stmt, 8, framework_property->dfTitle);
1169 _stmt_bind_int(mo_handler, stmt, 9, framework_property->dfType);
1170 _stmt_bind_text(mo_handler, stmt, 10, framework_property->dfType_Value);
1171 _stmt_bind_int(mo_handler, stmt, 11, mo_node_id);
1173 ret = _stmt_step(mo_handler, stmt);
1174 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
1175 ret = SYNC_AGENT_DM_MO_FAIL;
1180 _stmt_finalize(mo_handler, stmt);
1187 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)
1191 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1193 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1194 daci_stmt stmt = NULL;
1195 char *query = "select * from framework_property_tbl where node_id = ?";
1196 sync_agent_dm_mo_framework_property_s *temp_framework_property = 0;
1198 stmt = _query_prepare(mo_handler, query, strlen(query));
1200 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
1202 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
1203 temp_framework_property = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_framework_property_s *, sizeof(sync_agent_dm_mo_framework_property_s), 1);
1204 /* temp_framework_property->framework_property_id = _stmt_column_int(stmt, 0);*/
1205 temp_framework_property->accessType = _stmt_column_int(stmt, 1);
1206 temp_framework_property->defaultValue = _stmt_column_text(stmt, 2);
1207 temp_framework_property->description = _stmt_column_text(stmt, 3);
1208 temp_framework_property->dffFormat = _stmt_column_int(stmt, 4);
1209 temp_framework_property->occurrence = _stmt_column_int(stmt, 5);
1210 temp_framework_property->occurrence_num = _stmt_column_int(stmt, 6);
1211 temp_framework_property->scope = _stmt_column_int(stmt, 7);
1212 temp_framework_property->dfTitle = _stmt_column_text(stmt, 8);
1213 temp_framework_property->dfType = _stmt_column_int(stmt, 9);
1214 temp_framework_property->dfType_Value = _stmt_column_text(stmt, 10);
1215 /* temp_framework_property->node_id = _stmt_column_text(stmt, 9);*/
1217 ret = _stmt_finalize(mo_handler, stmt);
1219 ret = SYNC_AGENT_DM_MO_FAIL;
1222 (*framework_property) = temp_framework_property;
1229 sync_agent_dm_mo_error_e dm_mo_delete_all_framework_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
1233 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1235 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1236 daci_stmt stmt = NULL;
1239 query = "delete from framework_property_tbl";
1241 stmt = _query_prepare(mo_handler, query, strlen(query));
1243 ret = SYNC_AGENT_DM_MO_FAIL;
1247 ret = _stmt_step(mo_handler, stmt);
1252 _stmt_finalize(mo_handler, stmt);
1259 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)
1263 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1264 retvm_if(runtime_property == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_runtime_property_s is NULL !!");
1266 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1267 daci_stmt stmt = NULL;
1270 query = "insert into runtime_property_tbl " "(acl, format, name, size, title, t_stamp, type, type_value, ver_no, node_id) " "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
1272 stmt = _query_prepare(mo_handler, query, strlen(query));
1274 ret = SYNC_AGENT_DM_MO_FAIL;
1278 _stmt_bind_text(mo_handler, stmt, 1, runtime_property->acl);
1279 _stmt_bind_int(mo_handler, stmt, 2, runtime_property->format);
1280 _stmt_bind_text(mo_handler, stmt, 3, runtime_property->name);
1281 _stmt_bind_text(mo_handler, stmt, 4, runtime_property->size);
1282 _stmt_bind_text(mo_handler, stmt, 5, runtime_property->title);
1283 _stmt_bind_text(mo_handler, stmt, 6, runtime_property->tStamp);
1284 _stmt_bind_int(mo_handler, stmt, 7, runtime_property->type);
1285 _stmt_bind_text(mo_handler, stmt, 8, runtime_property->type_value);
1286 _stmt_bind_text(mo_handler, stmt, 9, runtime_property->verNo);
1287 _stmt_bind_int(mo_handler, stmt, 10, mo_node_id);
1289 ret = _stmt_step(mo_handler, stmt);
1290 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
1291 ret = SYNC_AGENT_DM_MO_FAIL;
1296 _stmt_finalize(mo_handler, stmt);
1303 sync_agent_dm_mo_error_e dm_mo_delete_runtime_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler, int mo_node_id)
1307 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1309 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1310 daci_stmt stmt = NULL;
1313 query = "delete from runtime_property_tbl where node_id = ?";
1315 stmt = _query_prepare(mo_handler, query, strlen(query));
1317 ret = SYNC_AGENT_DM_MO_FAIL;
1321 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
1322 ret = _stmt_step(mo_handler, stmt);
1327 _stmt_finalize(mo_handler, stmt);
1334 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)
1338 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1339 retvm_if(runtime_property == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_runtime_property_s is NULL !!");
1341 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1342 daci_stmt stmt = NULL;
1345 query = "update runtime_property_tbl set acl = ?, format = ?, name = ?, size = ?, title = ?," "t_stamp = ?, type = ?, type_value = ?, ver_no = ? where node_id = ?";
1347 stmt = _query_prepare(mo_handler, query, strlen(query));
1349 ret = SYNC_AGENT_DM_MO_FAIL;
1352 _stmt_bind_text(mo_handler, stmt, 1, runtime_property->acl);
1353 _stmt_bind_int(mo_handler, stmt, 2, runtime_property->format);
1354 _stmt_bind_text(mo_handler, stmt, 3, runtime_property->name);
1355 _stmt_bind_text(mo_handler, stmt, 4, runtime_property->size);
1356 _stmt_bind_text(mo_handler, stmt, 5, runtime_property->title);
1357 _stmt_bind_text(mo_handler, stmt, 6, runtime_property->tStamp);
1358 _stmt_bind_int(mo_handler, stmt, 7, runtime_property->type);
1359 _stmt_bind_text(mo_handler, stmt, 8, runtime_property->type_value);
1360 _stmt_bind_text(mo_handler, stmt, 9, runtime_property->verNo);
1361 _stmt_bind_int(mo_handler, stmt, 10, mo_node_id);
1363 ret = _stmt_step(mo_handler, stmt);
1364 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
1365 ret = SYNC_AGENT_DM_MO_FAIL;
1370 _stmt_finalize(mo_handler, stmt);
1377 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)
1381 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1383 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1384 daci_stmt stmt = NULL;
1385 char *query = "select * from runtime_property_tbl where node_id = ?";
1386 sync_agent_dm_mo_runtime_property_s *temp_runtime_property = 0;
1388 stmt = _query_prepare(mo_handler, query, strlen(query));
1390 _stmt_bind_int(mo_handler, stmt, 1, mo_node_id);
1392 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) {
1393 temp_runtime_property = SYNC_AGENT_DA_MEMORY_CALLOC(sync_agent_dm_mo_runtime_property_s *, sizeof(sync_agent_dm_mo_runtime_property_s), 1);
1394 /* temp_runtime_property->runtime_property_id = _stmt_column_int(stmt, 0);*/
1395 temp_runtime_property->acl = _stmt_column_text(stmt, 1);
1396 temp_runtime_property->format = _stmt_column_int(stmt, 2);
1397 temp_runtime_property->name = _stmt_column_text(stmt, 3);
1398 temp_runtime_property->size = _stmt_column_text(stmt, 4);
1399 temp_runtime_property->title = _stmt_column_text(stmt, 5);
1400 temp_runtime_property->tStamp = _stmt_column_text(stmt, 6);
1401 temp_runtime_property->type = _stmt_column_int(stmt, 7);
1402 temp_runtime_property->type_value = _stmt_column_text(stmt, 8);
1403 temp_runtime_property->verNo = _stmt_column_text(stmt, 9);
1404 /* temp_runtime_property->node_id = _stmt_column_text(stmt, 10);*/
1406 ret = _stmt_finalize(mo_handler, stmt);
1408 ret = SYNC_AGENT_DM_MO_FAIL;
1411 (*runtime_property) = temp_runtime_property;
1418 sync_agent_dm_mo_error_e dm_mo_delete_all_runtime_property(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
1422 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1424 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
1425 daci_stmt stmt = NULL;
1428 query = "delete from runtime_property_tbl";
1430 stmt = _query_prepare(mo_handler, query, strlen(query));
1432 ret = SYNC_AGENT_DM_MO_FAIL;
1436 ret = _stmt_step(mo_handler, stmt);
1441 _stmt_finalize(mo_handler, stmt);
1448 int _busy_handler(void *pData, int count)
1452 _DEBUG_ERROR("_busy_handler %d called", count);
1454 //retvm_if(pData == NULL, 0, "pData is NULL !!");
1455 warn_if(pData == NULL, "pData is NULL !!");
1457 /* sleep time when SQLITE_LOCK */
1463 /* retry will be stopped if busy handler return 0 */
1464 return SYNC_AGENT_DA_RETRY_COUNT - count;
1467 sync_agent_dm_mo_error_e _query_exec(SYNC_AGENT_DA_MO_HANDLER * mo_handler, char *query, char *err_msg)
1471 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1472 retvm_if(query == NULL, SYNC_AGENT_DM_MO_FAIL, "query is NULL !!");
1474 char *queryMsg = NULL;
1477 ret = sqlite3_exec(mo_handler, query, 0, 0, &queryMsg);
1478 if (ret != SQLITE_OK) {
1479 _DEBUG_ERROR("%s(%d) : %s", err_msg, ret, queryMsg);
1481 if (queryMsg != NULL)
1482 sqlite3_free(queryMsg);
1485 if (ret == SQLITE_BUSY)
1486 return SYNC_AGENT_DM_MO_FAIL;
1489 return SYNC_AGENT_DM_MO_FAIL;
1494 return SYNC_AGENT_DM_MO_SUCCESS;
1497 daci_stmt _query_prepare(SYNC_AGENT_DA_MO_HANDLER * mo_handler, char *query, int size)
1501 retvm_if(mo_handler == NULL, NULL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1502 retvm_if(query == NULL, NULL, "query is NULL !!");
1505 daci_stmt stmt = NULL;
1507 ret = sqlite3_prepare_v2(mo_handler, query, size, &stmt, 0);
1508 if (ret != SQLITE_OK)
1509 _DEBUG_ERROR("sqlite3_query_prepare failed(%d) : %s ", ret, sqlite3_errmsg(mo_handler));
1516 sync_agent_da_return_e _stmt_bind_text(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index, const char *value)
1520 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1524 if (value != NULL) {
1525 ret = sqlite3_bind_text(stmt, index, value, strlen(value), SQLITE_STATIC);
1527 ret = __stmt_bind_null(mo_handler, stmt, index);
1528 if (ret == SYNC_AGENT_DA_SUCCESS)
1532 if (ret != SQLITE_OK) {
1533 _DEBUG_ERROR("sqlite3_stmt_bind_text failed(%d) : %s ", ret, sqlite3_errmsg(mo_handler));
1534 return SYNC_AGENT_DA_ERR_QUERY_FAILED;
1539 return SYNC_AGENT_DA_SUCCESS;
1542 sync_agent_dm_mo_error_e _stmt_bind_int(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index, const int value)
1546 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1550 ret = sqlite3_bind_int(stmt, index, value);
1551 if (ret != SQLITE_OK) {
1552 _DEBUG_ERROR("sqlite3_stmt_bind_int failed(%d) : %s \n", ret, sqlite3_errmsg(mo_handler));
1553 return SYNC_AGENT_DM_MO_FAIL;
1558 return SYNC_AGENT_DM_MO_SUCCESS;
1561 sync_agent_dm_mo_error_e __stmt_bind_null(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt, int index)
1565 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1569 ret = sqlite3_bind_null(stmt, index);
1570 if (ret != SQLITE_OK) {
1571 _DEBUG_ERROR("sqlite3_stmt_bind_null failed(%d) : %s", ret, sqlite3_errmsg(mo_handler));
1572 return SYNC_AGENT_DM_MO_FAIL;
1577 return SYNC_AGENT_DM_MO_SUCCESS;
1580 sync_agent_da_return_e _stmt_step(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt)
1584 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1588 ret = sqlite3_step(stmt);
1590 if (ret == SQLITE_ROW)
1591 return SYNC_AGENT_DA_ERR_MORE_DATA;
1593 if (ret != SQLITE_DONE) {
1594 _DEBUG_ERROR("sqlite3_stmt_step failed(%d) : %s", ret, sqlite3_errmsg(mo_handler));
1596 /* if (ret == SQLITE_BUSY)
1597 return SYNC_AGENT_DM_MO_FAIL;*/
1599 return SYNC_AGENT_DM_MO_FAIL;
1604 return SYNC_AGENT_DM_MO_SUCCESS;
1607 sync_agent_dm_mo_error_e _stmt_finalize(SYNC_AGENT_DA_MO_HANDLER * mo_handler, daci_stmt stmt)
1611 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1615 if (sqlite3_finalize(stmt) != SQLITE_OK) {
1616 _DEBUG_ERROR("sqlite3_stmt_finalize failed(%d) : %s", ret, sqlite3_errmsg(mo_handler));
1617 return SYNC_AGENT_DM_MO_FAIL;
1622 return SYNC_AGENT_DM_MO_SUCCESS;
1625 char *_stmt_column_text(daci_stmt stmt, int index)
1629 retvm_if(stmt == NULL, NULL, "daci_stmt is NULL !!");
1632 temp = (char *)sqlite3_column_text(stmt, index);
1636 return SYNC_AGENT_DA_STRDUP(temp);
1639 int _stmt_column_int(daci_stmt stmt, int index)
1645 return (int)sqlite3_column_int(stmt, index);
1648 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)
1652 retvm_if(mo_handler == NULL, SYNC_AGENT_DM_MO_FAIL, "SYNC_AGENT_DA_MO_HANDLER is NULL !!");
1655 char *err_msg = NULL;
1657 ret = sqlite3_get_table(mo_handler, query, result, row_count, col_count, &err_msg);
1659 if (ret != SQLITE_OK) {
1660 _DEBUG_ERROR("sqlite3_get_table failed(%d) : %s", ret, err_msg);
1662 _free_table(*result);
1664 if (err_msg != NULL)
1665 sqlite3_free(err_msg);
1667 return SYNC_AGENT_DM_MO_FAIL;
1672 return SYNC_AGENT_DM_MO_SUCCESS;
1675 void _free_table(char **result)
1679 if (result != NULL) {
1680 sqlite3_free_table(result);
1687 static int _last_insert_id(SYNC_AGENT_DA_MO_HANDLER * mo_handler)
1693 return sqlite3_last_insert_rowid(mo_handler);
1696 int _exist_table(SYNC_AGENT_DA_MO_HANDLER * mo_handler, const char *table_name)
1700 daci_stmt stmt = NULL;
1701 int table_count = 0;
1702 char *query = "select count(*) from sqlite_master where tbl_name= ?";
1704 stmt = _query_prepare(mo_handler, query, strlen(query));
1705 if ((stmt != NULL) && (_stmt_bind_text(mo_handler, stmt, 1, table_name) == SYNC_AGENT_DA_ERR_MORE_DATA)) {
1707 if (_stmt_step(mo_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA)
1708 table_count = _stmt_column_int(stmt, 0);
1710 _stmt_finalize(mo_handler, stmt);
1712 if (table_count > 0) {
1723 static char *_extract_dmacc_name(const char *mo_full_path)
1727 char *dmacc_name = NULL;
1730 const char *cursor = mo_full_path;
1731 const char *start_point = NULL;
1732 while (cursor != NULL) {
1733 cursor = strchr(cursor, '/');
1734 if (cursor == NULL) {
1741 start_point = cursor;
1742 } else if (cnt == 3) {
1743 int len = cursor - start_point + 2;
1745 dmacc_name = (char *)calloc(len, sizeof(char));
1746 if (dmacc_name == NULL) {
1747 _DEBUG_ERROR("CALLOC failed !!!");
1750 strncpy(dmacc_name, start_point, len - 1);