Code Sync up from tizen_2.4 08/36908/1
authorDongchul Lim <dc7.lim@samsung.com>
Tue, 17 Mar 2015 04:45:14 +0000 (13:45 +0900)
committerDongchul Lim <dc7.lim@samsung.com>
Tue, 17 Mar 2015 04:45:14 +0000 (13:45 +0900)
Change-Id: I58654321b598dbebe5fdbe211aeba98205617a38

AUTHORS [new file with mode: 0644]
CMakeLists.txt
README [new file with mode: 0644]
packaging/tel-plugin-database.manifest [deleted file]
packaging/tel-plugin-database.spec
src/database_main.c
tel-plugin-database.manifest [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..0e9faa9
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,6 @@
+Jongman Park <jman.park@samsung.com>
+Ja-young Gu <jygu@samsung.com>
+Kyeongchul Kim <kyeongchul.kim@samsung.com>
+DongHoo Park <donghoo.park@samsung.>
+Youngman Park <youngman.park@samsung.com>
+Inho Oh <inho48.oh@samsung.com>
index ada97b2..098e54b 100644 (file)
@@ -11,7 +11,7 @@ SET(CMAKE_INSTALL_PREFIX "${PREFIX}")
 
 # Set required packages
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED glib-2.0 tcore tel-headers db-util)
+pkg_check_modules(pkgs REQUIRED glib-2.0 tcore db-util)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -20,15 +20,25 @@ ENDFOREACH(flag)
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wextra -fvisibility=hidden -fPIC")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -O2 -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -Wcast-qual -Wall -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable")
+
+### Purge unused code ###
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections") 
 
 ADD_DEFINITIONS("-DFEATURE_TLOG_DEBUG")
-ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"DATABASE\"")
+ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"SP_DB\"")
+ADD_DEFINITIONS("-DPLUGIN_VERSION=${VERSION}")
+ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))")
 
 MESSAGE(${CMAKE_C_FLAGS})
-MESSAGE(${CMAKE_EXE_LINKER_FLAGS})
+MESSAGE(${pkgs_LDFLAGS})
 
-SET(SRCS src/database_main.c)
+SET(SRCS
+               src/database_main.c
+)
 
 
 # library build
@@ -40,5 +50,5 @@ SET_TARGET_PROPERTIES(db-plugin PROPERTIES PREFIX "" OUTPUT_NAME db-plugin)
 
 # install
 INSTALL(TARGETS db-plugin
-       LIBRARY DESTINATION ${LIB_INSTALL_DIR}/telephony/plugins)
+               LIBRARY DESTINATION lib/telephony/plugins)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME tel-plugin-database)
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..fde8c86
--- /dev/null
+++ b/README
@@ -0,0 +1,2 @@
+database access plug-in
+DongHoo Park - evilpanda
\ No newline at end of file
diff --git a/packaging/tel-plugin-database.manifest b/packaging/tel-plugin-database.manifest
deleted file mode 100644 (file)
index 017d22d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
-    <domain name="_"/>
- </request>
-</manifest>
index c96f9bf..f959884 100644 (file)
@@ -1,46 +1,42 @@
-%define major 3
-%define minor 0
-%define patchlevel 1
-
-Name: tel-plugin-database
-Summary: Telephony DataBase storage plugin
-Version:    %{major}.%{minor}.%{patchlevel}
-Release:    1
-Group:      System/Libraries
-License:    Apache-2.0
-Source0:    tel-plugin-database-%{version}.tar.gz
-Source1001:    tel-plugin-database.manifest
-Requires(post): /sbin/ldconfig
-Requires(postun): /sbin/ldconfig
+%define major 0
+%define minor 1
+%define patchlevel 12
+
+Name:           tel-plugin-database
+Version:        %{major}.%{minor}.%{patchlevel}
+Release:        1
+License:        Apache
+Summary:        Telephony DataBase storage plugin
+Group:          System/Libraries
+Source0:        tel-plugin-database-%{version}.tar.gz
 BuildRequires:  cmake
+BuildRequires:  pkgconfig(db-util)
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(tcore)
-BuildRequires:  pkgconfig(tel-headers)
-BuildRequires:  pkgconfig(db-util)
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
 
 %description
 Telephony DataBase storage plugin
 
 %prep
 %setup -q
-cp %{SOURCE1001} .
 
 %build
-%cmake .
-make %{?jobs:-j%jobs}
+versionint=$[%{major} * 1000000 + %{minor} * 1000 + %{patchlevel}]
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DVERSION=$versionint
+make %{?_smp_mflags}
 
-%post
-/sbin/ldconfig
+%post -p /sbin/ldconfig
 
 %postun -p /sbin/ldconfig
 
 %install
 %make_install
-mkdir -p %{buildroot}/usr/share/license
-cp LICENSE %{buildroot}/usr/share/license/%{name}
+mkdir -p %{buildroot}%{_datadir}/license
 
 %files
-%manifest %{name}.manifest
 %defattr(-,root,root,-)
+#%doc COPYING
 %{_libdir}/telephony/plugins/db-plugin*
-/usr/share/license/%{name}
+%{_datadir}/license/tel-plugin-database
index c33e6c5..8943dd9 100755 (executable)
@@ -1,7 +1,9 @@
 /*
  * tel-plugin-database
  *
- * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: DongHoo Park <donghoo.park@samsung.com>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,6 +16,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
+ *
  */
 
 #include <stdio.h>
 #include <plugin.h>
 #include <storage.h>
 
-static void *create_handle(TcoreStorage *strg, const char *path)
+#ifndef PLUGIN_VERSION
+#define PLUGIN_VERSION 1
+#endif
+
+static void* create_handle(Storage *strg, const char *path)
 {
        int rv = 0;
        sqlite3 *handle = NULL;
@@ -43,12 +50,10 @@ static void *create_handle(TcoreStorage *strg, const char *path)
        return handle;
 }
 
-static gboolean remove_handle(TcoreStorage *strg, void *handle)
+static gboolean remove_handle(Storage *strg, void *handle)
 {
-       if (!handle) {
-               err("handle is null");
+       if (!handle)
                return FALSE;
-       }
 
        db_util_close(handle);
        //free(handle);
@@ -57,44 +62,45 @@ static gboolean remove_handle(TcoreStorage *strg, void *handle)
        return TRUE;
 }
 
-static gboolean update_query_database(TcoreStorage *strg, void *handle,
-               const char *query, GHashTable *in_param)
+static gboolean update_query_database(Storage *strg, void *handle, const char *query, GHashTable *in_param)
 {
        int rv = 0;
        sqlite3_stmt* stmt = NULL;
-       char sz_query[1000+1] = {0, };
+       char szQuery[1000+1];   // +1 is for NULL Termination Character '\0'
+
        GHashTableIter iter;
        gpointer key, value;
 
        dbg("update query");
 
-       memset(sz_query, '\0', 1001);
-       strncpy(sz_query, query, 1000);
+       memset(szQuery, '\0', 1001);
+       strncpy(szQuery, query, 1000);
 
-       rv = sqlite3_prepare_v2(handle, sz_query, strlen(sz_query), &stmt, NULL);
+       rv = sqlite3_prepare_v2(handle, szQuery, strlen(szQuery), &stmt, NULL);
        if (rv != SQLITE_OK) {
                err("fail to connect to table (%d)", rv);
                return FALSE;
        }
 
-       g_hash_table_iter_init(&iter, in_param);
-       while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
-               dbg("key(%s), value(%s)", (const char*)key, (const char*)value);
-
-               if (!value || g_strcmp0((const char*) value, "") == 0) {
-                       dbg("bind null");
-                       rv = sqlite3_bind_null(stmt, atoi((const char*) key));
-               } else {
-                       dbg("bind value");
-                       rv = sqlite3_bind_text(stmt, atoi((const char*) key),
-                                       (const char*) value,
-                                       strlen((const char*) value),
-                                       SQLITE_STATIC);
-               }
+       if(in_param){
+               g_hash_table_iter_init(&iter, in_param);
+               while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+                       dbg("key(%s), value(%s)", (const char*)key, (const char*)value);
+
+                       if (!value || g_strcmp0((const char*) value, "") == 0) {
+                               dbg("bind null");
+                               rv = sqlite3_bind_null(stmt, atoi((const char*) key));
+                       }
+                       else {
+                               dbg("bind value");
+                               rv = sqlite3_bind_text(stmt, atoi((const char*) key), (const char*) value, strlen((const char*) value),
+                                               SQLITE_STATIC);
+                       }
 
-               if (rv != SQLITE_OK) {
-                       err("fail to bind data (%d)", rv);
-                       return FALSE;
+                       if (rv != SQLITE_OK) {
+                               dbg("fail to bind data (%d)", rv);
+                               return FALSE;
+                       }
                }
        }
 
@@ -109,22 +115,22 @@ static gboolean update_query_database(TcoreStorage *strg, void *handle,
        return TRUE;
 }
 
-static gboolean read_query_database(TcoreStorage *strg, void *handle,
-               const char *query, GHashTable *in_param,
+static gboolean read_query_database(Storage *strg, void *handle, const char *query, GHashTable *in_param,
                GHashTable *out_param, int out_param_cnt)
 {
-       int rv = 0, index = 0, outter_index = 0;
-       sqlite3_stmt *stmt = NULL;
-       char sz_query[5000+1] = {0, };
+       int rv = 0, local_index = 0, outter_index = 0;
+       sqlite3_stmt* stmt = NULL;
+       char szQuery[5000+1];   // +1 is for NULL Termination Character '\0'
+
        GHashTableIter iter;
        gpointer key, value;
 
        dbg("read query");
 
-       memset(sz_query, '\0', 5001);
-       strncpy(sz_query, query, 5000);
+       memset(szQuery, '\0', 5001);
+       strncpy(szQuery, query, 5000);
 
-       rv = sqlite3_prepare_v2(handle, sz_query, strlen(sz_query), &stmt, NULL);
+       rv = sqlite3_prepare_v2(handle, szQuery, strlen(szQuery), &stmt, NULL);
        if (rv != SQLITE_OK) {
                err("fail to connect to table (%d)", rv);
                return FALSE;
@@ -133,24 +139,20 @@ static gboolean read_query_database(TcoreStorage *strg, void *handle,
        if (in_param) {
                g_hash_table_iter_init(&iter, in_param);
                while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
-                       dbg("key(%s), value(%s)",
-                               (const char*)key, (const char*)value);
+                       dbg("key(%s), value(%s)", (const char*)key, (const char*)value);
 
                        if (!value || g_strcmp0((const char*) value, "") == 0) {
                                dbg("bind null");
-                               rv = sqlite3_bind_null(stmt,
-                                               atoi((const char*) key));
-                       else {
+                               rv = sqlite3_bind_null(stmt, atoi((const char*) key));
+                       }
+                       else {
                                dbg("bind value");
-                               rv = sqlite3_bind_text(stmt,
-                                               atoi((const char*) key),
-                                               (const char*) value,
-                                               strlen((const char*) value),
+                               rv = sqlite3_bind_text(stmt, atoi((const char*) key), (const char*) value, strlen((const char*) value),
                                                SQLITE_STATIC);
                        }
 
                        if (rv != SQLITE_OK) {
-                               err("fail to bind data (%d)", rv);
+                               dbg("fail to bind data (%d)", rv);
                                return FALSE;
                        }
                }
@@ -160,68 +162,71 @@ static gboolean read_query_database(TcoreStorage *strg, void *handle,
        dbg("read query executed (%d)", rv);
 
        while (rv == SQLITE_ROW) {
+
                char tmp_key_outter[10];
                GHashTable *out_param_data;
 
-               out_param_data = g_hash_table_new_full(g_str_hash,
-                                       g_str_equal, NULL, g_free);
+               out_param_data = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
 
-               for (index = 0; index < out_param_cnt; index++) {
-                       char *tmp = NULL, tmp_key[10];
-                       tmp = (char *) sqlite3_column_text(stmt, index);
-                       snprintf(tmp_key, sizeof(tmp_key), "%d", index);
-                       g_hash_table_insert(out_param_data, g_strdup(tmp_key),
-                                       g_strdup(tmp));
+               for (local_index = 0; local_index < out_param_cnt; local_index++) {
+                       char tmp_key[10];
+                       const unsigned char *tmp;
+                       tmp = sqlite3_column_text(stmt, local_index);
+                       snprintf(tmp_key, sizeof(tmp_key), "%d", local_index);
+                       g_hash_table_insert(out_param_data, g_strdup(tmp_key), g_strdup((const gchar *) tmp));
                }
+
                snprintf(tmp_key_outter, sizeof(tmp_key_outter), "%d", outter_index);
                g_hash_table_insert(out_param, g_strdup(tmp_key_outter), out_param_data);
                outter_index++;
                rv = sqlite3_step(stmt);
        }
+
        sqlite3_finalize(stmt);
        return TRUE;
 }
 
-static gboolean insert_query_database(TcoreStorage *strg, void *handle,
-               const char *query, GHashTable *in_param)
+static gboolean insert_query_database(Storage *strg, void *handle, const char *query, GHashTable *in_param)
 {
        int rv = 0;
-       sqlite3_stmt *stmt = NULL;
-       char sz_query[5000+1] = {0, };
+       sqlite3_stmt* stmt = NULL;
+       char szQuery[5000+1];   // +1 is for NULL Termination Character '\0'
+
        GHashTableIter iter;
        gpointer key, value;
-
        dbg("insert query");
 
-       memset(sz_query, '\0', 5001);
-       strncpy(sz_query, query, 5000);
+       memset(szQuery, '\0', 5001);
+       strncpy(szQuery, query, 5000);
 
-       rv = sqlite3_prepare_v2(handle, sz_query, strlen(sz_query), &stmt, NULL);
+       rv = sqlite3_prepare_v2(handle, szQuery, strlen(szQuery), &stmt, NULL);
        if (rv != SQLITE_OK) {
                err("fail to connect to table (%d)", rv);
                return FALSE;
        }
 
-       g_hash_table_iter_init(&iter, in_param);
-       while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
-               dbg("key(%s), value(%s)", (const char*)key, (const char*)value);
-
-               if (!value || g_strcmp0((const char*) value, "") == 0) {
-                       dbg("bind null");
-                       rv = sqlite3_bind_null(stmt, atoi((const char*) key));
-               } else {
-                       dbg("bind value");
-                       rv = sqlite3_bind_text(stmt, atoi((const char*) key),
-                                       (const char*) value,
-                                       strlen((const char*) value),
-                                       SQLITE_STATIC);
-               }
+       if(in_param){
+               g_hash_table_iter_init(&iter, in_param);
+               while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+                       dbg("key(%s), value(%s)", (const char*)key, (const char*)value);
 
-               if (rv != SQLITE_OK) {
-                       err("fail to bind data (%d)", rv);
-                       return FALSE;
+                       if (!value || g_strcmp0((const char*) value, "") == 0) {
+                               dbg("bind null");
+                               rv = sqlite3_bind_null(stmt, atoi((const char*) key));
+                       }
+                       else {
+                               dbg("bind value");
+                               rv = sqlite3_bind_text(stmt, atoi((const char*) key), (const char*) value, strlen((const char*) value),
+                                               SQLITE_STATIC);
+                       }
+
+                       if (rv != SQLITE_OK) {
+                               dbg("fail to bind data (%d)", rv);
+                               return FALSE;
+                       }
                }
        }
+
        rv = sqlite3_step(stmt);
        dbg("insert query executed (%d)", rv);
        sqlite3_finalize(stmt);
@@ -232,46 +237,47 @@ static gboolean insert_query_database(TcoreStorage *strg, void *handle,
        return TRUE;
 }
 
-static gboolean remove_query_database(TcoreStorage *strg, void *handle,
-               const char *query, GHashTable *in_param)
+static gboolean remove_query_database(Storage *strg, void *handle, const char *query, GHashTable *in_param)
 {
        int rv = 0;
-       sqlite3_stmt *stmt = NULL;
-       char sz_query[1000+1] = {0, };
+       sqlite3_stmt* stmt = NULL;
+       char szQuery[1000+1];   // +1 is for NULL Termination Character '\0'
+
        GHashTableIter iter;
        gpointer key, value;
-
        dbg("remove query");
 
-       memset(sz_query, '\0', 1001);
-       strncpy(sz_query, query, 1000);
+       memset(szQuery, '\0', 1001);
+       strncpy(szQuery, query, 1000);
 
-       rv = sqlite3_prepare_v2(handle, sz_query, strlen(sz_query), &stmt, NULL);
+       rv = sqlite3_prepare_v2(handle, szQuery, strlen(szQuery), &stmt, NULL);
        if (rv != SQLITE_OK) {
                err("fail to connect to table (%d)", rv);
                return FALSE;
        }
 
-       g_hash_table_iter_init(&iter, in_param);
-       while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
-               dbg("key(%s), value(%s)", (const char*)key, (const char*)value);
-
-               if (!value || g_strcmp0((const char*) value, "") == 0) {
-                       dbg("bind null");
-                       rv = sqlite3_bind_null(stmt, atoi((const char*) key));
-               } else {
-                       dbg("bind value");
-                       rv = sqlite3_bind_text(stmt, atoi((const char*) key),
-                                       (const char*) value,
-                                       strlen((const char*) value),
-                                       SQLITE_STATIC);
-               }
+       if(in_param){
+               g_hash_table_iter_init(&iter, in_param);
+               while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+                       dbg("key(%s), value(%s)", (const char*)key, (const char*)value);
 
-               if (rv != SQLITE_OK) {
-                       err("fail to bind data (%d)", rv);
-                       return FALSE;
+                       if (!value || g_strcmp0((const char*) value, "") == 0) {
+                               dbg("bind null");
+                               rv = sqlite3_bind_null(stmt, atoi((const char*) key));
+                       }
+                       else {
+                               dbg("bind value");
+                               rv = sqlite3_bind_text(stmt, atoi((const char*) key), (const char*) value, strlen((const char*) value),
+                                               SQLITE_STATIC);
+                       }
+
+                       if (rv != SQLITE_OK) {
+                               dbg("fail to bind data (%d)", rv);
+                               return FALSE;
+                       }
                }
        }
+
        rv = sqlite3_step(stmt);
        dbg("remove query executed (%d)", rv);
        sqlite3_finalize(stmt);
@@ -279,10 +285,11 @@ static gboolean remove_query_database(TcoreStorage *strg, void *handle,
        if (rv != SQLITE_DONE) {
                return FALSE;
        }
+
        return TRUE;
 }
 
-TcoreStorageOperations storage_ops = {
+static struct storage_operations ops = {
        .create_handle = create_handle,
        .remove_handle = remove_handle,
        .update_query_database = update_query_database,
@@ -299,11 +306,12 @@ static gboolean on_load()
 
 static gboolean on_init(TcorePlugin *p)
 {
-       tcore_check_return_value_assert(p != NULL, FALSE);
+       if (!p)
+               return FALSE;
 
-       tcore_storage_new(p, "database", &storage_ops);
+       tcore_storage_new(p, "database", &ops);
 
-       dbg("database plug-in init done !!");
+       dbg("finish to initialize database plug-in");
        return TRUE;
 }
 
@@ -313,11 +321,11 @@ static void on_unload(TcorePlugin *p)
        return;
 }
 
-struct tcore_plugin_define_desc plugin_define_desc =
+EXPORT_API struct tcore_plugin_define_desc plugin_define_desc =
 {
        .name = "DATABASE",
        .priority = TCORE_PLUGIN_PRIORITY_HIGH -1,
-       .version = 1,
+       .version = PLUGIN_VERSION,
        .load = on_load,
        .init = on_init,
        .unload = on_unload
diff --git a/tel-plugin-database.manifest b/tel-plugin-database.manifest
new file mode 100644 (file)
index 0000000..97e8c31
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_"/>
+       </request>
+</manifest>