2 * Copyright 2012 Samsung Electronics Co., Ltd
\r
4 * Licensed under the Flora License, Version 1.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.tizenopensource.org/license
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 using namespace std;
\r
20 #include "browser-user-agent-db.h"
\r
22 sqlite3* Browser_User_Agent_DB::m_db_descriptor = NULL;
\r
24 Browser_User_Agent_DB::Browser_User_Agent_DB(void)
\r
26 BROWSER_LOGD("[%s]", __func__);
\r
29 Browser_User_Agent_DB::~Browser_User_Agent_DB(void)
\r
31 BROWSER_LOGD("[%s]", __func__);
\r
34 Eina_Bool Browser_User_Agent_DB::_open_db(void)
\r
36 BROWSER_LOGD("[%s]", __func__);
\r
37 int error = db_util_open(BROWSER_USER_AGENT_DB_PATH, &m_db_descriptor, DB_UTIL_REGISTER_HOOK_METHOD);
\r
38 if (error != SQLITE_OK) {
\r
39 db_util_close(m_db_descriptor);
\r
40 m_db_descriptor = NULL;
\r
47 Eina_Bool Browser_User_Agent_DB::_close_db(void)
\r
49 BROWSER_LOGD("[%s]", __func__);
\r
50 if (m_db_descriptor)
\r
52 int error = db_util_close(m_db_descriptor);
\r
53 if (error != SQLITE_OK) {
\r
54 BROWSER_LOGE("db_util_close error");
\r
55 m_db_descriptor = NULL;
\r
58 m_db_descriptor = NULL;
\r
64 Eina_Bool Browser_User_Agent_DB::get_user_agent(const char *title, char *&user_agent)
\r
66 BROWSER_LOGD("[%s]", __func__);
\r
68 if(!strcmp(title, "System user agent")){
\r
69 user_agent = vconf_get_str(VCONFKEY_ADMIN_UAGENT);
\r
71 BROWSER_LOGE("vconf_get_str(VCONFKEY_ADMIN_UAGENT) failed.");
\r
77 if (_open_db() == EINA_FALSE)
\r
80 sqlite3_stmt *sqlite3_stmt = NULL;
\r
81 int error = sqlite3_prepare_v2(m_db_descriptor, "select value from user_agents where name=?",
\r
82 -1, &sqlite3_stmt, NULL);
\r
83 if (error != SQLITE_OK) {
\r
84 BROWSER_LOGD("SQL error=%d", error);
\r
85 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
86 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
91 if (sqlite3_bind_text(sqlite3_stmt, 1, title, -1, NULL) != SQLITE_OK)
\r
92 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
94 error = sqlite3_step(sqlite3_stmt);
\r
97 if (error == SQLITE_ROW)
\r
98 value = reinterpret_cast<const char*>(sqlite3_column_text(sqlite3_stmt, 0));
\r
100 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
101 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
103 if (!value.empty())
\r
104 user_agent = strdup(value.c_str());
\r
110 return (error == SQLITE_DONE || error == SQLITE_ROW);
\r