diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2019-04-17 20:35:28 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2019-04-18 07:55:36 +0900 |
commit | 37f7f3c49f6dee73aef30d74a58c2c4f04428472 (patch) | |
tree | cce6ffb2426720364ba699b72e5bb3de63ec60cd | |
parent | ddefce70fda6f8fd84857c55c7c3cfc7fbe17d26 (diff) | |
download | syspopup-37f7f3c49f6dee73aef30d74a58c2c4f04428472.tar.gz syspopup-37f7f3c49f6dee73aef30d74a58c2c4f04428472.tar.bz2 syspopup-37f7f3c49f6dee73aef30d74a58c2c4f04428472.zip |
Modified sp_initdb tool
After this patch is applied, sp_initdb tool supports xml parser.
If the developer adds the xml file of the syspopup on
/usr/share/syspopup/<profile>/ directory, the tool parses the data and
inserts it into syspopup db.
Change-Id: I4f4714562d3dda271e50dd438a9e3972b327a4df
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | packaging/syspopup.spec | 49 | ||||
-rw-r--r-- | tool/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tool/sp_initdb.c | 312 | ||||
-rw-r--r-- | tool/sp_initdb/CMakeLists.txt | 51 | ||||
-rw-r--r-- | tool/sp_initdb/data/common.xml.in | 25 | ||||
-rw-r--r-- | tool/sp_initdb/data/ivi.xml.in | 25 | ||||
-rw-r--r-- | tool/sp_initdb/data/mobile.xml.in | 25 | ||||
-rw-r--r-- | tool/sp_initdb/data/tv.xml.in | 25 | ||||
-rw-r--r-- | tool/sp_initdb/data/wearable.xml.in | 17 | ||||
-rw-r--r-- | tool/sp_initdb/inc/syspopup_parser.h | 24 | ||||
-rw-r--r-- | tool/sp_initdb/inc/syspopup_parser_db.h | 33 | ||||
-rw-r--r-- | tool/sp_initdb/inc/syspopup_private.h | 70 | ||||
-rw-r--r-- | tool/sp_initdb/inc/syspopup_type.h | 32 | ||||
-rw-r--r-- | tool/sp_initdb/manifest.xsd.in | 57 | ||||
-rw-r--r-- | tool/sp_initdb/src/sp_initdb.c | 157 | ||||
-rw-r--r-- | tool/sp_initdb/src/syspopup_parser.c | 390 | ||||
-rw-r--r-- | tool/sp_initdb/src/syspopup_parser_db.c | 211 | ||||
-rw-r--r-- | tool/sp_initdb/src/syspopup_type.c | 41 | ||||
-rw-r--r-- | tool/sp_initdb/xml.xsd.in | 5 |
20 files changed, 1243 insertions, 317 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7726297..6790036 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) PROJECT(syspopup_mods C) diff --git a/packaging/syspopup.spec b/packaging/syspopup.spec index 2378bda..b332f53 100644 --- a/packaging/syspopup.spec +++ b/packaging/syspopup.spec @@ -24,6 +24,9 @@ BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(libsmack) +BuildRequires: pkgconfig(libxml-2.0) + +Requires(posttrans): /usr/bin/rm %define upgrade_script_path /usr/share/upgrade/scripts @@ -68,6 +71,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -DEXTRA_CFLAGS=-fPIC \ -DFULLVER=%{version} \ -DMAJORVER=${MAJORVER} \ + -DSYSCONFDIR=%{_sysconfdir} \ . make %{?jobs:-j%jobs} @@ -91,6 +95,49 @@ cp -f scripts/502.syspopup_upgrade.sh %{buildroot}%{upgrade_script_path} %posttrans /usr/bin/sp_initdb +if [ -e %{_sysconfdir}/config/model-config.xml ]; then + PROFILE=`grep "feature\/profile" %{_sysconfdir}/config/model-config.xml` + if [[ "${PROFILE}" == *"mobile"* ]]; then + rm -rf %{_datarootdir}/syspopup/wearable + rm -rf %{_datarootdir}/syspopup/tv + rm -rf %{_datarootdir}/syspopup/common + rm -rf %{_datarootdir}/syspopup/ivi + elif [[ "${PROFILE}" == *"wearable"* ]]; then + rm -rf %{_datarootdir}/syspopup/mobile + rm -rf %{_datarootdir}/syspopup/tv + rm -rf %{_datarootdir}/syspopup/common + rm -rf %{_datarootdir}/syspopup/ivi + elif [[ "${PROFILE}" == *"tv"* ]]; then + rm -rf %{_datarootdir}/syspopup/mobile + rm -rf %{_datarootdir}/syspopup/wearable + rm -rf %{_datarootdir}/syspopup/common + rm -rf %{_datarootdir}/syspopup/ivi + elif [[ "${PROFILE}" == *"common"* ]]; then + rm -rf %{_datarootdir}/syspopup/mobile + rm -rf %{_datarootdir}/syspopup/wearable + rm -rf %{_datarootdir}/syspopup/tv + rm -rf %{_datarootdir}/syspopup/ivi + elif [[ "${PROFILE}" == *"ivi"* ]]; then + rm -rf %{_datarootdir}/syspopup/mobile + rm -rf %{_datarootdir}/syspopup/wearable + rm -rf %{_datarootdir}/syspopup/tv + rm -rf %{_datarootdir}/syspopup/common + else + rm -rf %{_datarootdir}/syspopup/mobile + rm -rf %{_datarootdir}/syspopup/wearable + rm -rf %{_datarootdir}/syspopup/tv + rm -rf %{_datarootdir}/syspopup/common + rm -rf %{_datarootdir}/syspopup/ivi + + fi +else + rm -rf %{_datarootdir}/syspopup/mobile + rm -rf %{_datarootdir}/syspopup/wearable + rm -rf %{_datarootdir}/syspopup/tv + rm -rf %{_datarootdir}/syspopup/common + rm -rf %{_datarootdir}/syspopup/ivi +fi + %files %manifest %{name}.manifest %defattr(-,root,root,-) @@ -100,6 +147,8 @@ cp -f scripts/502.syspopup_upgrade.sh %{buildroot}%{upgrade_script_path} %{_datadir}/popup_noti_term %license LICENSE %{upgrade_script_path}/502.syspopup_upgrade.sh +%{_sysconfdir}/syspopup/preload/* +%{_prefix}/share/syspopup/* %files devel %manifest %{name}-devel.manifest diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt index 04515e7..c692952 100644 --- a/tool/CMakeLists.txt +++ b/tool/CMakeLists.txt @@ -1,4 +1,5 @@ -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) pkg_check_modules(PKGS REQUIRED libtzplatform-config @@ -12,11 +13,11 @@ FOREACH(FLAGS ${PKGS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") ENDFOREACH(FLAGS) +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/syspopup-caller) add_executable(sp_test test.c) target_link_libraries(sp_test syspopup_caller ${pkgs_LDFLAGS} "-pie") INSTALL(TARGETS sp_test DESTINATION bin) -ADD_EXECUTABLE(sp_initdb sp_initdb.c) -TARGET_LINK_LIBRARIES(sp_initdb ${PKGS_LDFLAGS} "-pie") -INSTALL(TARGETS sp_initdb DESTINATION bin) +ADD_SUBDIRECTORY(sp_initdb) diff --git a/tool/sp_initdb.c b/tool/sp_initdb.c deleted file mode 100644 index 8083b93..0000000 --- a/tool/sp_initdb.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * 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. - */ - -#define _GNU_SOURCE -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/smack.h> -#include <glib.h> -#include <sqlite3.h> -#include <tzplatform_config.h> -#include <system_info.h> - -#define CREATE_SYSPOPUP_INFO_TABLE \ -"PRAGMA journal_mode = PERSIST; " \ -"CREATE TABLE IF NOT EXISTS syspopup_info ( " \ -" id INTEGER PRIMARY KEY, " \ -" name TEXT UNIQUE NOT NULL, " \ -" prio INTEGER, " \ -" focus INTEGER, " \ -" timeout INTEGER, " \ -" term_act INTEGER, " \ -" endkey_act INTEGER, " \ -" pkgname TEXT NOT NULL);" - -#define QUERY_INSERT_SYSPOPUP_INFO \ -"INSERT OR REPLACE INTO syspopup_info " \ -"(name, prio, focus, timeout, term_act, endkey_act, pkgname) " \ -"VALUES(?, ?, ?, ?, ?, ?, ?);" - -#define PATH_DB tzplatform_mkpath(TZ_SYS_DB, ".syspopup.db") -#define PATH_DB_JOURNAL tzplatform_mkpath(TZ_SYS_DB, ".syspopup.db-journal") -#define ARRAY_SIZE(x) ((sizeof(x)) / (sizeof(x[0]))) -#define DB_LABEL "User::Home" -#define ROOT_UID 0 - -struct syspopup_info { - const char *name; - int prio; - int focus; - int timeout; - int term_act; - int endkey_act; - const char *appid; -}; - -static sqlite3 *db; -static struct syspopup_info default_info[] = { - {"volume", 1, 1, -1, 1, 1, "org.tizen.volume"}, - {"bt-syspopup", 0, 0, -1, 0, 0, "org.tizen.bt-syspopup"}, - {"wifi-qs", 0, 0, -1, 0, 2, "net.wifi-qs"}, - {"powerkey-syspopup", 3, 0, -1, 0, 0, "org.tizen.powerkey-syspopup"}, - {"overheat-syspopup", 3, 0, -1, 0, 0, "org.tizen.overheat-syspopup"}, - {"lowmem-syspopup", 0, 0, 5, 0, 0, "org.tizen.lowmem-syspopup"}, - {"battery-syspopup", 0, 0, 5, 0, 0, "org.tizen.battery-syspopup"}, - {"net-popup", 0, 0, -1, 0, 0, "org.tizen.net-popup"}, - {"usb-syspopup", 1, 0, -1, 2, 2, "org.tizen.usb-syspopup"}, - {"usbotg-syspopup", 0, 1, -1, 0, 0, "org.tizen.usbotg-syspopup"}, - {"mmc-syspopup", 0, 0, -1, 0, 0, "org.tizen.mmc-syspopup"}, - {"mobileap-syspopup", 0, 0, -1, 0, 0, "org.tizen.mobileap-syspopup"}, - {"telephony-syspopup", 1, 1, 5, 0, 0, "org.tizen.telephony-syspopup"}, - {"system-syspopup", 1, 0, -1, 0, 0, "org.tizen.system-syspopup"}, - {"safetyvolume-syspopup", 1, 0, -1, 0, 0, "org.tizen.safetyvolume-syspopup"}, - {"datausage-syspopup", 1, 0, -1, 0, 0, "org.tizen.datausage-syspopup"}, - {"crash-syspopup", 1, 0, -1, 0, 0, "org.tizen.crash-syspopup"}, - {"gps-syspopup", 0, 0, -1, 0, 0, "org.tizen.gps-syspopup"}, - {"mode-syspopup", 1, 0, -1, 0, 0, "org.tizen.mode-syspopup"}, - {"d2d-conv-syspopup", 3, 0, -1, 0, 0, "org.tizen.d2d-conv-syspopup"}, - {"fido-syspopup", 3, 0, -1, 0, 0, "org.tizen.fido-syspopup"} -}; -static struct syspopup_info wearable_info[] = { - {"volume", 1, 1, -1, 1, 1, "org.tizen.windicator"}, - {"powerkey-syspopup", 3, 0, -1, 0, 0, "org.tizen.powerkey-syspopup"}, - {"lowmem-syspopup", 0, 0, 5, 0, 0, "org.tizen.lowmem-syspopup"}, - {"battery-syspopup", 0, 0, 5, 0, 0, "org.tizen.battery-syspopup"}, - {"system-syspopup", 1, 0, -1, 0, 0, "org.tizen.system-syspopup"}, - {"safetyvolume-syspopup", 3, 1, -1, 0, 0, "org.tizen.safetyvolume-syspopup"}, - {"crash-syspopup", 1, 0, -1, 0, 0, "org.tizen.crash-syspopup"}, - {"wc-syspopup", 0, 0, -1, 0, 0, "net.wc-syspopup"}, - {"bt-syspopup", 0, 0, -1, 0, 0, "org.tizen.bt-syspopup"}, - {"d2d-conv-syspopup", 3, 0, -1, 0, 0, "org.tizen.d2d-conv-syspopup"}, - {"fido-syspopup", 3, 0, -1, 0, 0, "org.tizen.fido-syspopup"}, - {"telephony-syspopup", 1, 1, 5, 0, 0, "org.tizen.telephony-syspopup"}, - {"net-popup", 0, 0, -1, 0, 0, "org.tizen.net-popup"}, -}; - -static int __unlink_db(void) -{ - int ret; - - ret = access(PATH_DB, F_OK); - if (ret == 0) { - ret = unlink(PATH_DB); - if (ret != 0) { - printf("Failed to delete %s\n", PATH_DB); - return -1; - } - } - - return 0; -} - -static void __close_db(void) -{ - if (db == NULL) - return; - - sqlite3_close(db); - db = NULL; -} - -static int __open_db(void) -{ - int ret; - const char *query = CREATE_SYSPOPUP_INFO_TABLE; - char *err_msg = NULL; - - ret = sqlite3_open_v2(PATH_DB, &db, - SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL); - if (ret != SQLITE_OK) { - printf("Failed to create syspopup db - ret(%d), errmsg(%s)\n", - ret, sqlite3_errmsg(db)); - return -1; - } - - ret = sqlite3_exec(db, query, NULL, NULL, &err_msg); - if (ret != SQLITE_OK) { - printf("Failed to create syspopup info table(%s)\n", err_msg); - sqlite3_free(err_msg); - __close_db(); - return -1; - } - - ret = smack_setlabel(PATH_DB, DB_LABEL, SMACK_LABEL_ACCESS); - if (ret < 0) { - printf("Failed to set label\n"); - __close_db(); - return -1; - } - - if (access(PATH_DB_JOURNAL, F_OK) == 0) { - ret = smack_setlabel(PATH_DB_JOURNAL, DB_LABEL, SMACK_LABEL_ACCESS); - if (ret < 0) { - printf("Failed to set label of journal file\n"); - __close_db(); - return -1; - } - } - - return 0; -} - -static int __insert_syspopup_info(struct syspopup_info *info) -{ - int ret; - int result = 0; - sqlite3_stmt *stmt = NULL; - const char *query = QUERY_INSERT_SYSPOPUP_INFO; - - if (info == NULL) - return -1; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) - return -1; - - ret = sqlite3_bind_text(stmt, 1, info->name, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - result = -1; - goto end; - } - - ret = sqlite3_bind_int(stmt, 2, info->prio); - if (ret != SQLITE_OK) { - result = -1; - goto end; - } - - ret = sqlite3_bind_int(stmt, 3, info->focus); - if (ret != SQLITE_OK) { - result = -1; - goto end; - } - - ret = sqlite3_bind_int(stmt, 4, info->timeout); - if (ret != SQLITE_OK) { - result = -1; - goto end; - } - - ret = sqlite3_bind_int(stmt, 5, info->term_act); - if (ret != SQLITE_OK) { - result = -1; - goto end; - } - - ret = sqlite3_bind_int(stmt, 6, info->endkey_act); - if (ret != SQLITE_OK) { - result = -1; - goto end; - } - - ret = sqlite3_bind_text(stmt, 7, info->appid, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - result = -1; - goto end; - } - - ret = sqlite3_step(stmt); - if (ret != SQLITE_DONE) - result = -1; - -end: - sqlite3_finalize(stmt); - - return result; -} - -static int __init_db(void) -{ - int ret; - struct syspopup_info *info; - unsigned int info_size; - unsigned int i; - char *profile = NULL; - - system_info_get_platform_string("http://tizen.org/feature/profile", - &profile); - if (profile == NULL) { - printf("Failed to get profile info\n"); - return -1; - } - - if (*profile == 'w' || *profile == 'W') { - info = wearable_info; - info_size = ARRAY_SIZE(wearable_info); - } else { - info = default_info; - info_size = ARRAY_SIZE(default_info); - } - free(profile); - - ret = __open_db(); - if (ret < 0) - return -1; - - for (i = 0; i < info_size; i++) { - ret = __insert_syspopup_info(&info[i]); - if (ret < 0) - break; - } - - __close_db(); - - return 0; -} - -int main(int argc, char **argv) -{ - int ret; - GOptionContext *context; - GError *error = NULL; - gpointer opt_force = NULL; - GOptionEntry entries[] = { - {"force", 'f', 0, G_OPTION_ARG_NONE, &opt_force, "Remove an existing db file and initialize it", NULL}, - {NULL} - }; - - if (getuid() != ROOT_UID) { - printf("This binary should be run as root user\n"); - return -1; - } - - context = g_option_context_new(NULL); - g_option_context_add_main_entries(context, entries, NULL); - if (!g_option_context_parse(context, &argc, &argv, &error)) { - printf("%s: %s\n", argv[0], error->message); - g_option_context_free(context); - g_clear_error(&error); - return -1; - } - g_option_context_free(context); - - if (opt_force) { - ret = __unlink_db(); - if (ret < 0) - return -1; - } else { - ret = access(PATH_DB, F_OK); - if (ret == 0) { - printf("The db(%s) file already exists.\n", PATH_DB); - return 0; - } - } - - return __init_db(); -} diff --git a/tool/sp_initdb/CMakeLists.txt b/tool/sp_initdb/CMakeLists.txt new file mode 100644 index 0000000..a953ffa --- /dev/null +++ b/tool/sp_initdb/CMakeLists.txt @@ -0,0 +1,51 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + +PROJECT(syspopup_initdb C) + +ADD_DEFINITIONS("-DSYSCONFDIR=\"${SYSCONFDIR}\"") +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc) + +INCLUDE(FindPkgConfig) + +pkg_check_modules(INITDB_PKGS REQUIRED + libtzplatform-config + capi-system-info + sqlite3 + libsmack + glib-2.0 + libxml-2.0 + ) +FOREACH(FLAGS ${INITDB_PKGS_CFLAGS}) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") +ENDFOREACH(FLAGS) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +AUX_SOURCE_DIRECTORY(src INITDB_SRCS) + +ADD_EXECUTABLE(sp_initdb ${INITDB_SRCS}) +TARGET_LINK_LIBRARIES(sp_initdb ${INITDB_PKGS_LDFLAGS} "-pie") + +CONFIGURE_FILE(manifest.xsd.in manifest.xsd @ONLY) +CONFIGURE_FILE(xml.xsd.in xml.xsd @ONLY) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/mobile.xml.in mobile.xml @ONLY) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/wearable.xml.in wearable.xml @ONLY) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/tv.xml.in tv.xml @ONLY) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/common.xml.in common.xml @ONLY) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/ivi.xml.in ivi.xml @ONLY) + +INSTALL(TARGETS sp_initdb DESTINATION bin) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.xsd DESTINATION ${SYSCONFDIR}/syspopup/preload/) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/xml.xsd DESTINATION ${SYSCONFDIR}/syspopup/preload/) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/mobile.xml DESTINATION share/syspopup/mobile) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/wearable.xml DESTINATION share/syspopup/wearable) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/tv.xml DESTINATION share/syspopup/tv) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/common.xml DESTINATION share/syspopup/common) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ivi.xml DESTINATION share/syspopup/ivi) diff --git a/tool/sp_initdb/data/common.xml.in b/tool/sp_initdb/data/common.xml.in new file mode 100644 index 0000000..020e09f --- /dev/null +++ b/tool/sp_initdb/data/common.xml.in @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<manifest xmlns="http://tizen.org/ns/packages" version="5.5"> + <profile name="common"/> + <syspopup name="volume" priority="medium" focus="false" timeout="-1" term-action="hide" endkey-action="hide" appid="org.tizen.volume"/> + <syspopup name="bt-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.bt-syspopup"/> + <syspopup name="wifi-qs" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="ignore" appid="net.wifi-qs"/> + <syspopup name="powerkey-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.powerkey-syspopup"/> + <syspopup name="overheat-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.overheat-syspopup"/> + <syspopup name="lowmem-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.lowmem-syspopup"/> + <syspopup name="battery-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.battery-syspopup"/> + <syspopup name="net-popup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.net-popup"/> + <syspopup name="usb-syspopup" priority="medium" focus="true" timeout="-1" term-action="ignore" endkey-action="ignore" appid="org.tizen.usb-syspopup"/> + <syspopup name="usbotg-syspopup" priority="default" focus="false" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.usbotg-syspopup"/> + <syspopup name="mmc-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mmc-syspopup"/> + <syspopup name="mobileap-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mobileap-syspopup"/> + <syspopup name="telephony-syspopup" priority="medium" focus="false" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.telephony-syspopup"/> + <syspopup name="system-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.system-syspopup"/> + <syspopup name="safetyvolume-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.safetyvolume-syspopup"/> + <syspopup name="datausage-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.datausage-syspopup"/> + <syspopup name="crash-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.crash-syspopup"/> + <syspopup name="gps-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.gps-syspopup"/> + <syspopup name="mode-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mode-syspopup"/> + <syspopup name="d2d-conv-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.d2d-conv-syspopup"/> + <syspopup name="fido-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.fido-syspopup"/> +</manifest> diff --git a/tool/sp_initdb/data/ivi.xml.in b/tool/sp_initdb/data/ivi.xml.in new file mode 100644 index 0000000..5913468 --- /dev/null +++ b/tool/sp_initdb/data/ivi.xml.in @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<manifest xmlns="http://tizen.org/ns/packages" version="5.5"> + <profile name="ivi"/> + <syspopup name="volume" priority="medium" focus="false" timeout="-1" term-action="hide" endkey-action="hide" appid="org.tizen.volume"/> + <syspopup name="bt-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.bt-syspopup"/> + <syspopup name="wifi-qs" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="ignore" appid="net.wifi-qs"/> + <syspopup name="powerkey-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.powerkey-syspopup"/> + <syspopup name="overheat-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.overheat-syspopup"/> + <syspopup name="lowmem-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.lowmem-syspopup"/> + <syspopup name="battery-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.battery-syspopup"/> + <syspopup name="net-popup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.net-popup"/> + <syspopup name="usb-syspopup" priority="medium" focus="true" timeout="-1" term-action="ignore" endkey-action="ignore" appid="org.tizen.usb-syspopup"/> + <syspopup name="usbotg-syspopup" priority="default" focus="false" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.usbotg-syspopup"/> + <syspopup name="mmc-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mmc-syspopup"/> + <syspopup name="mobileap-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mobileap-syspopup"/> + <syspopup name="telephony-syspopup" priority="medium" focus="false" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.telephony-syspopup"/> + <syspopup name="system-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.system-syspopup"/> + <syspopup name="safetyvolume-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.safetyvolume-syspopup"/> + <syspopup name="datausage-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.datausage-syspopup"/> + <syspopup name="crash-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.crash-syspopup"/> + <syspopup name="gps-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.gps-syspopup"/> + <syspopup name="mode-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mode-syspopup"/> + <syspopup name="d2d-conv-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.d2d-conv-syspopup"/> + <syspopup name="fido-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.fido-syspopup"/> +</manifest> diff --git a/tool/sp_initdb/data/mobile.xml.in b/tool/sp_initdb/data/mobile.xml.in new file mode 100644 index 0000000..1d7b47e --- /dev/null +++ b/tool/sp_initdb/data/mobile.xml.in @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<manifest xmlns="http://tizen.org/ns/packages" version="5.5"> + <profile name="mobile"/> + <syspopup name="volume" priority="medium" focus="false" timeout="-1" term-action="hide" endkey-action="hide" appid="org.tizen.volume"/> + <syspopup name="bt-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.bt-syspopup"/> + <syspopup name="wifi-qs" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="ignore" appid="net.wifi-qs"/> + <syspopup name="powerkey-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.powerkey-syspopup"/> + <syspopup name="overheat-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.overheat-syspopup"/> + <syspopup name="lowmem-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.lowmem-syspopup"/> + <syspopup name="battery-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.battery-syspopup"/> + <syspopup name="net-popup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.net-popup"/> + <syspopup name="usb-syspopup" priority="medium" focus="true" timeout="-1" term-action="ignore" endkey-action="ignore" appid="org.tizen.usb-syspopup"/> + <syspopup name="usbotg-syspopup" priority="default" focus="false" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.usbotg-syspopup"/> + <syspopup name="mmc-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mmc-syspopup"/> + <syspopup name="mobileap-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mobileap-syspopup"/> + <syspopup name="telephony-syspopup" priority="medium" focus="false" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.telephony-syspopup"/> + <syspopup name="system-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.system-syspopup"/> + <syspopup name="safetyvolume-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.safetyvolume-syspopup"/> + <syspopup name="datausage-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.datausage-syspopup"/> + <syspopup name="crash-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.crash-syspopup"/> + <syspopup name="gps-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.gps-syspopup"/> + <syspopup name="mode-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mode-syspopup"/> + <syspopup name="d2d-conv-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.d2d-conv-syspopup"/> + <syspopup name="fido-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.fido-syspopup"/> +</manifest> diff --git a/tool/sp_initdb/data/tv.xml.in b/tool/sp_initdb/data/tv.xml.in new file mode 100644 index 0000000..7f90281 --- /dev/null +++ b/tool/sp_initdb/data/tv.xml.in @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<manifest xmlns="http://tizen.org/ns/packages" version="5.5"> + <profile name="tv"/> + <syspopup name="volume" priority="medium" focus="false" timeout="-1" term-action="hide" endkey-action="hide" appid="org.tizen.volume"/> + <syspopup name="bt-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.bt-syspopup"/> + <syspopup name="wifi-qs" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="ignore" appid="net.wifi-qs"/> + <syspopup name="powerkey-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.powerkey-syspopup"/> + <syspopup name="overheat-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.overheat-syspopup"/> + <syspopup name="lowmem-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.lowmem-syspopup"/> + <syspopup name="battery-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.battery-syspopup"/> + <syspopup name="net-popup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.net-popup"/> + <syspopup name="usb-syspopup" priority="medium" focus="true" timeout="-1" term-action="ignore" endkey-action="ignore" appid="org.tizen.usb-syspopup"/> + <syspopup name="usbotg-syspopup" priority="default" focus="false" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.usbotg-syspopup"/> + <syspopup name="mmc-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mmc-syspopup"/> + <syspopup name="mobileap-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mobileap-syspopup"/> + <syspopup name="telephony-syspopup" priority="medium" focus="false" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.telephony-syspopup"/> + <syspopup name="system-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.system-syspopup"/> + <syspopup name="safetyvolume-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.safetyvolume-syspopup"/> + <syspopup name="datausage-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.datausage-syspopup"/> + <syspopup name="crash-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.crash-syspopup"/> + <syspopup name="gps-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.gps-syspopup"/> + <syspopup name="mode-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.mode-syspopup"/> + <syspopup name="d2d-conv-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.d2d-conv-syspopup"/> + <syspopup name="fido-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.fido-syspopup"/> +</manifest> diff --git a/tool/sp_initdb/data/wearable.xml.in b/tool/sp_initdb/data/wearable.xml.in new file mode 100644 index 0000000..446ef32 --- /dev/null +++ b/tool/sp_initdb/data/wearable.xml.in @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<manifest xmlns="http://tizen.org/ns/packages" version="5.5"> + <profile name="mobile"/> + <syspopup name="volume" priority="medium" focus="false" timeout="-1" term-action="hide" endkey-action="hide" appid="org.tizen.windicator"/> + <syspopup name="powerkey-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.powerkey-syspopup"/> + <syspopup name="lowmem-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.lowmem-syspopup"/> + <syspopup name="battery-syspopup" priority="default" focus="true" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.battery-syspopup"/> + <syspopup name="system-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.system-syspopup"/> + <syspopup name="safetyvolume-syspopup" priority="top" focus="false" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.safetyvolume-syspopup"/> + <syspopup name="crash-syspopup" priority="medium" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.crash-syspopup"/> + <syspopup name="wc-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="net.wc-syspopup"/> + <syspopup name="bt-syspopup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.bt-syspopup"/> + <syspopup name="d2d-conv-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.d2d-conv-syspopup"/> + <syspopup name="fido-syspopup" priority="top" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.fido-syspopup"/> + <syspopup name="telephony-syspopup" priority="medium" focus="false" timeout="5" term-action="term" endkey-action="term" appid="org.tizen.telephony-syspopup"/> + <syspopup name="net-popup" priority="default" focus="true" timeout="-1" term-action="term" endkey-action="term" appid="org.tizen.net-popup"/> +</manifest> diff --git a/tool/sp_initdb/inc/syspopup_parser.h b/tool/sp_initdb/inc/syspopup_parser.h new file mode 100644 index 0000000..a077f15 --- /dev/null +++ b/tool/sp_initdb/inc/syspopup_parser.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#ifndef __SYSPOPUP_PARSER_H__ +#define __SYSPOPUP_PARSER_H__ + +#include <glib.h> + +int syspopup_parser_parse(const char *manifest, GList **syspopup_list); + +#endif /* __SYSPOPUP_PARSER_H__ */ diff --git a/tool/sp_initdb/inc/syspopup_parser_db.h b/tool/sp_initdb/inc/syspopup_parser_db.h new file mode 100644 index 0000000..9e356cc --- /dev/null +++ b/tool/sp_initdb/inc/syspopup_parser_db.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#ifndef __SYSPOPUP_PARSER_DB_H__ +#define __SYSPOPUP_PARSER_DB_H__ + +#include <stdbool.h> +#include <glib.h> + +bool syspopup_parser_db_exist(void); + +int syspopup_parser_db_unlink(void); + +void syspopup_parser_db_close(void); + +int syspopup_parser_db_open(void); + +int syspopup_parser_db_insert(GList *syspopup_list); + +#endif /* __SYSPOPUP_PARSER_DB_H__ */ diff --git a/tool/sp_initdb/inc/syspopup_private.h b/tool/sp_initdb/inc/syspopup_private.h new file mode 100644 index 0000000..aabc223 --- /dev/null +++ b/tool/sp_initdb/inc/syspopup_private.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#ifndef __SYSPOPUP_PRIVATE_H__ +#define __SYSPOPUP_PRIVATE_H__ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include <stdio.h> +#include <libgen.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "SYSPOPUP" + +#ifdef _E +#undef _E +#endif + +#define _E(fmt, ...) \ + fprintf(stderr, "E/%s: %s: %s(%d) > "fmt"\n", \ + LOG_TAG, basename(__FILE__), __FUNCTION__, __LINE__, \ + ##__VA_ARGS__) + +#ifdef _W +#undef _W +#endif + +#define _W(fmt, ...) \ + fprintf(stderr, "W/%s: %s: %s(%d) > "fmt"\n", \ + LOG_TAG, basename(__FILE__), __FUNCTION__, __LINE__, \ + ##__VA_ARGS__) + +#ifdef _I +#undef _I +#endif + +#define _I(fmt, ...) \ + fprintf(stdout, "I/%s: %s: %s(%d) > "fmt"\n", \ + LOG_TAG, basename(__FILE__), __FUNCTION__, __LINE__, \ + ##__VA_ARGS__) + +#ifdef _D +#undef _D +#endif + +#define _D(fmt, ...) \ + fprintf(stdout, "D/%s: %s: %s(%d) > "fmt"\n", \ + LOG_TAG, basename(__FILE__), __FUNCTION__, __LINE__, \ + ##__VA_ARGS__) + + +#endif /* __SYSPOPUP_PRIVATE_H__ */ diff --git a/tool/sp_initdb/inc/syspopup_type.h b/tool/sp_initdb/inc/syspopup_type.h new file mode 100644 index 0000000..f52c28d --- /dev/null +++ b/tool/sp_initdb/inc/syspopup_type.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#ifndef __SYSPOPUP_TYPE_H__ +#define __SYSPOPUP_TYPE_H__ + +typedef struct { + char *name; + char *appid; + int priority; + int focus; + int timeout; + int term_action; + int endkey_action; +} syspopup_t; + +void syspopup_free(syspopup_t *syspopup); + +#endif /* __SYSPOPUP_TYPE_H__ */ diff --git a/tool/sp_initdb/manifest.xsd.in b/tool/sp_initdb/manifest.xsd.in new file mode 100644 index 0000000..f930359 --- /dev/null +++ b/tool/sp_initdb/manifest.xsd.in @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tizen.org/ns/packages" xmlns:packages="http://tizen.org/ns/packages"> + <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/> + + <xs:element name="manifest"> + <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element ref="packages:syspopup"/> + <xs:element ref="packages:author"/> + <xs:element ref="packages:label"/> + <xs:element ref="packages:description"/> + <xs:element ref="packages:profile"/> + <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax"/> + </xs:choice> + <xs:attribute name="version" use="required" type="xs:string"/> + <xs:anyAttribute namespace="##any" processContents="lax"/> + </xs:complexType> + </xs:element> + + <xs:element name="author"> + <xs:complexType mixed="true"> + <xs:attribute name="email"/> + <xs:attribute name="href"/> + <xs:attribute ref="xml:lang"/> + <xs:anyAttribute namespace="##any" processContents="lax"/> + </xs:complexType> + </xs:element> + <xs:element name="description"> + <xs:complexType mixed="true"> + <xs:attribute ref="xml:lang"/> + <xs:anyAttribute namespace="##any" processContents="lax"/> + </xs:complexType> + </xs:element> + <xs:element name="profile"> + <xs:complexType> + <xs:attribute name="name" use="required" type="xs:string"/> + <xs:anyAttribute namespace="##any" processContents="lax"/> + </xs:complexType> + </xs:element> + <xs:element name="label"> + </xs:element> + <xs:element name="syspopup"> + <xs:complexType> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax"/> + </xs:choice> + <xs:attribute name="name" use="required" type="xs:string"/> + <xs:attribute name="appid" use="required" type="xs:string"/> + <xs:attribute name="priority" use="required" type="xs:string"/> + <xs:attribute name="focus" use="required" type="xs:boolean"/> + <xs:attribute name="timeout" use="required" type="xs:integer"/> + <xs:attribute name="term-action" use="required" type="xs:string"/> + <xs:attribute name="endkey-action" use="required" type="xs:string"/> + <xs:anyAttribute namespace="##any" processContents="lax"/> + </xs:complexType> + </xs:element> + </xs:schema> diff --git a/tool/sp_initdb/src/sp_initdb.c b/tool/sp_initdb/src/sp_initdb.c new file mode 100644 index 0000000..2eb519e --- /dev/null +++ b/tool/sp_initdb/src/sp_initdb.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/smack.h> +#include <linux/limits.h> +#include <glib.h> +#include <system_info.h> + +#include "syspopup_private.h" +#include "syspopup_parser_db.h" +#include "syspopup_parser.h" +#include "syspopup_type.h" + +#define PATH_SYSPOPUP_DEFAULT "/usr/share/syspopup/default" + +#define PATH_SYSPOPUP "/usr/share/syspopup" + +#define ROOT_UID 0 + +static int __load_syspopup_info(const char *path, GList **syspopup_list) +{ + struct dirent *dentry = NULL; + char buf[PATH_MAX]; + char *ext; + DIR *dp; + + if (!path) + return -1; + + dp = opendir(path); + if (!dp) { + printf("Failed to open directory(%s). errno(%d)\n", + path, errno); + return -1; + } + + while ((dentry = readdir(dp)) != NULL) { + if (dentry->d_name[0] == '.') + continue; + + ext = strrchr(dentry->d_name, '.'); + if (ext && strcmp(ext, ".xml") == 0) { + snprintf(buf, sizeof(buf), "%s/%s", + path, dentry->d_name); + syspopup_parser_parse(buf, syspopup_list); + } + } + closedir(dp); + + return 0; +} + +static const char *__get_syspopup_path(void) +{ + static char path[PATH_MAX]; + char *profile = NULL; + + if (access(PATH_SYSPOPUP_DEFAULT, F_OK) == 0) + return PATH_SYSPOPUP_DEFAULT; + + system_info_get_platform_string("http://tizen.org/feature/profile", + &profile); + if (profile == NULL) { + printf("Failed to get profile info\n"); + snprintf(path, sizeof(path), "%s/mobile", PATH_SYSPOPUP); + return path; + } + + snprintf(path, sizeof(path), "%s/%s", PATH_SYSPOPUP, profile); + free(profile); + + return path; +} + +static int __init_db(void) +{ + GList *list = NULL; + int ret; + + ret = __load_syspopup_info(__get_syspopup_path(), &list); + if (ret < 0) + goto end; + + ret = syspopup_parser_db_open(); + if (ret < 0) + goto end; + + ret = syspopup_parser_db_insert(list); + +end: + syspopup_parser_db_close(); + + if (list) + g_list_free_full(list, (GDestroyNotify)syspopup_free); + + return ret; +} + +int main(int argc, char **argv) +{ + int ret; + GOptionContext *context; + GError *error = NULL; + gpointer opt_force = NULL; + GOptionEntry entries[] = { + {"force", 'f', 0, G_OPTION_ARG_NONE, &opt_force, + "Remove an existing db file and initialize it", NULL}, + {NULL} + }; + + if (getuid() != ROOT_UID) { + printf("This binary should be run as root user\n"); + return -1; + } + + context = g_option_context_new(NULL); + g_option_context_add_main_entries(context, entries, NULL); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + printf("%s: %s\n", argv[0], error->message); + g_option_context_free(context); + g_clear_error(&error); + return -1; + } + g_option_context_free(context); + + if (opt_force) { + ret = syspopup_parser_db_unlink(); + if (ret < 0) + return -1; + } else { + if (syspopup_parser_db_exist()) { + printf("The db file already exists.\n"); + return 0; + } + } + + return __init_db(); +} diff --git a/tool/sp_initdb/src/syspopup_parser.c b/tool/sp_initdb/src/syspopup_parser.c new file mode 100644 index 0000000..1e74186 --- /dev/null +++ b/tool/sp_initdb/src/syspopup_parser.c @@ -0,0 +1,390 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> +#include <ctype.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/smack.h> + +#include <glib.h> +#include <libxml/parser.h> +#include <libxml/xmlschemas.h> + +#include "syspopup_private.h" +#include "syspopup_parser.h" +#include "syspopup_type.h" + +#define SCHEMA_FILE SYSCONFDIR "/syspopup/preload/manifest.xsd" + +typedef enum { + SYSPOPUP_ATTR_NONE, + SYSPOPUP_ATTR_NAME, + SYSPOPUP_ATTR_APPID, + SYSPOPUP_ATTR_PRIORITY, + SYSPOPUP_ATTR_FOCUS, + SYSPOPUP_ATTR_TIMEOUT, + SYSPOPUP_ATTR_TERM_ACTION, + SYSPOPUP_ATTR_ENDKEY_ACTION, + SYSPOPUP_ATTR_MAX, +} syspopup_attr_e; + +typedef int (*syspopup_parser_func)(xmlNodePtr node, void *user_data); + +static int __check_manifest_validation(const char *manifest) +{ + xmlSchemaParserCtxtPtr ctx; + xmlSchemaValidCtxtPtr vctx; + xmlSchemaPtr xschema; + int ret; + + if (!manifest) { + _E("Invalid parameter"); + return -1; + } + + ctx = xmlSchemaNewParserCtxt(SCHEMA_FILE); + if (!ctx) { + _E("xmlSchemaNewParserCtxt() is failed. manifest(%s)", + manifest); + return -1; + } + + xschema = xmlSchemaParse(ctx); + if (!xschema) { + _E("xmlSchemaParse() is failed. manifest(%s)", manifest); + xmlSchemaFreeParserCtxt(ctx); + return -1; + } + + vctx = xmlSchemaNewValidCtxt(xschema); + if (!vctx) { + _E("xmlSchemaNewValidCtxt() is failed. manifest(%s)", + manifest); + xmlSchemaFree(xschema); + xmlSchemaFreeParserCtxt(ctx); + return -1; + } + + xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc)fprintf, + (xmlSchemaValidityWarningFunc)fprintf, stderr); + + ret = xmlSchemaValidateFile(vctx, manifest, 0); + if (ret == -1) { + _E("xmlSchemaValidateFile() is failed. manifest(%s)", manifest); + } else if (ret == 0) { + _D("Manifest is valid. manifest(%s)", manifest); + } else { + _E("Manifest Validation Failed with error code %d", ret); + ret = -1; + } + + xmlSchemaFreeValidCtxt(vctx); + xmlSchemaFree(xschema); + xmlSchemaFreeParserCtxt(ctx); + + return ret; +} + +static char *__get_attr(xmlNodePtr node, const char *name) +{ + xmlChar *val; + char *attr = NULL; + + val = xmlGetProp(node, (const xmlChar *)name); + if (val) { + attr = strdup((char *)val); + xmlFree(val); + } + + return attr; +} + +static int __syspopup_attr_name(xmlNodePtr node, void *user_data) +{ + syspopup_t *info = (syspopup_t *)user_data; + char *name; + + name = __get_attr(node, "name"); + if (!name) { + _E("Failed to get attribute name"); + return -1; + } + + info->name = name; + + return 0; +} + +static int __syspopup_attr_appid(xmlNodePtr node, void *user_data) +{ + syspopup_t *info = (syspopup_t *)user_data; + char *appid; + + appid = __get_attr(node, "appid"); + if (!appid) { + _E("Failed to get attribute appid"); + return -1; + } + + info->appid = appid; + + return 0; +} + +static int __priority_to_integer(const char *priority) +{ + if (!strcasecmp(priority, "default")) + return 0; + else if (!strcasecmp(priority, "medium")) + return 1; + else if (!strcasecmp(priority, "high")) + return 2; + else if (!strcasecmp(priority, "top")) + return 3; + + return -1; +} + +static int __syspopup_attr_priority(xmlNodePtr node, void *user_data) +{ + syspopup_t *info = (syspopup_t *)user_data; + char *priority; + + priority = __get_attr(node, "priority"); + if (!priority) { + _E("Failed to get attribute priority"); + return -1; + } + + info->priority = __priority_to_integer(priority); + if (info->priority < 0) { + _E("Priority(%s) attribute must be 'default' or 'medium' or " + "'high' or 'top'", priority); + free(priority); + return -1; + } + free(priority); + + return 0; +} + +static bool __is_boolean(const char *value) +{ + if (!strcasecmp(value, "true") || !strcasecmp(value, "false")) + return true; + + return false; +} + +static int __syspopup_attr_focus(xmlNodePtr node, void *user_data) +{ + syspopup_t *info = (syspopup_t *)user_data; + char *focus; + + focus = __get_attr(node, "focus"); + if (!focus) { + _E("Failed to get attribute focus"); + return -1; + } + + if (!__is_boolean(focus)) { + _E("focus(%s) attribute must be 'true' or 'false'", focus); + free(focus); + return -1; + } + + if (!strcasecmp(focus, "true")) + info->focus = 0; + else + info->focus = 1; + + free(focus); + + return 0; +} + +static int __syspopup_attr_timeout(xmlNodePtr node, void *user_data) +{ + syspopup_t *info = (syspopup_t *)user_data; + char *timeout; + + timeout = __get_attr(node, "timeout"); + if (!timeout) { + _E("Failed to get attribute timeout"); + return -1; + } + + info->timeout = atoi(timeout); + free(timeout); + + return 0; +} + +static int __action_to_integer(const char *action) +{ + if (!strcasecmp(action, "term")) + return 0; + else if (!strcasecmp(action, "hide")) + return 1; + else if (!strcasecmp(action, "ignore")) + return 2; + + return -1; +} + +static int __syspopup_attr_term_action(xmlNodePtr node, void *user_data) +{ + syspopup_t *info = (syspopup_t *)user_data; + char *term_action; + + term_action = __get_attr(node, "term-action"); + if (!term_action) { + _E("Failed to get attribute term-action"); + return -1; + } + + info->term_action = __action_to_integer(term_action); + if (info->term_action < 0) { + _E("term-action(%s) attribute must be 'term' or 'hide' or " + "'ignore'", term_action); + free(term_action); + return -1; + } + free(term_action); + + return 0; +} + +static int __syspopup_attr_endkey_action(xmlNodePtr node, void *user_data) +{ + syspopup_t *info = (syspopup_t *)user_data; + char *endkey_action; + + endkey_action = __get_attr(node, "endkey-action"); + if (!endkey_action) { + _E("Failed to get attribute term-action"); + return -1; + } + + info->endkey_action = __action_to_integer(endkey_action); + if (info->endkey_action < 0) { + _E("endkey-action(%s) attribute must be 'term' or 'hide' or " + "'ignore'", endkey_action); + free(endkey_action); + return -1; + } + free(endkey_action); + + return 0; +} + +static syspopup_parser_func __attr_table[] = { + [SYSPOPUP_ATTR_NAME] = __syspopup_attr_name, + [SYSPOPUP_ATTR_APPID] = __syspopup_attr_appid, + [SYSPOPUP_ATTR_PRIORITY] = __syspopup_attr_priority, + [SYSPOPUP_ATTR_FOCUS] = __syspopup_attr_focus, + [SYSPOPUP_ATTR_TIMEOUT] = __syspopup_attr_timeout, + [SYSPOPUP_ATTR_TERM_ACTION] = __syspopup_attr_term_action, + [SYSPOPUP_ATTR_ENDKEY_ACTION] = __syspopup_attr_endkey_action, +}; + +static int __parse_syspopup(xmlNodePtr node, syspopup_t **syspopup) +{ + syspopup_t *info; + int ret; + int i; + + info = calloc(1, sizeof(syspopup_t)); + if (!info) { + _E("Out of memory"); + return -1; + } + + for (i = SYSPOPUP_ATTR_NONE; i < SYSPOPUP_ATTR_MAX; i++) { + if (!__attr_table[i]) + continue; + + ret = __attr_table[i](node, info); + if (ret < 0) { + _E("Failed to parse attribute %d", i); + syspopup_free(info); + return -1; + } + } + + *syspopup = info; + + return 0; +} + +int syspopup_parser_parse(const char *manifest, GList **syspopup_list) +{ + GList *list = NULL; + xmlDocPtr doc; + xmlNodePtr root; + xmlNodePtr node; + syspopup_t *info; + int ret; + + if (!manifest || !syspopup_list) { + _E("Invalid parameter"); + return -1; + } + + ret = __check_manifest_validation(manifest); + if (ret < 0) + return -1; + + doc = xmlParseFile(manifest); + if (!doc) { + _E("Failed to parse %s", manifest); + return -1; + } + + root = xmlDocGetRootElement(doc); + if (!root) { + _E("Failed to get root element %s", manifest); + xmlFreeDoc(doc); + return -1; + } + + for (node = root->children; node; node = node->next) { + if (!node->name) + continue; + + if (strcmp((char *)node->name, "syspopup") != 0) + continue; + + info = NULL; + ret = __parse_syspopup(node, &info); + if (ret < 0) { + _E("Failed to parse syspopup"); + continue; + } + + list = g_list_append(list, info); + } + + *syspopup_list = list; + xmlFreeDoc(doc); + + return 0; +} diff --git a/tool/sp_initdb/src/syspopup_parser_db.c b/tool/sp_initdb/src/syspopup_parser_db.c new file mode 100644 index 0000000..9a98dc6 --- /dev/null +++ b/tool/sp_initdb/src/syspopup_parser_db.c @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/smack.h> +#include <errno.h> + +#include <glib.h> +#include <sqlite3.h> +#include <tzplatform_config.h> +#include <system_info.h> + +#include "syspopup_parser_db.h" +#include "syspopup_private.h" +#include "syspopup_type.h" + +#define CREATE_SYSPOPUP_INFO_TABLE \ + "PRAGMA journal_mode = PERSIST; " \ + "CREATE TABLE IF NOT EXISTS syspopup_info ( " \ + "id INTEGER PRIMARY KEY, " \ + "name TEXT UNIQUE NOT NULL, " \ + "prio INTEGER, " \ + "focus INTEGER, " \ + "timeout INTEGER, " \ + "term_act INTEGER, " \ + "endkey_act INTEGER, " \ + "pkgname TEXT NOT NULL);" + +#define QUERY_INSERT_SYSPOPUP_INFO \ + "INSERT OR REPLACE INTO syspopup_info " \ + "(name, prio, focus, timeout, term_act, endkey_act, pkgname) " \ + "VALUES(?, ?, ?, ?, ?, ?, ?);" + +#define BIND_TEXT(db, stmt, i, text) do { \ + if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\ + _E("sqlite3_bind_text() is failed. error(%s)", \ + sqlite3_errmsg(db)); \ + sqlite3_finalize(stmt); \ + return -1; \ + } \ +} while (0) + +#define BIND_INT(db, stmt, i, val) do { \ + if (sqlite3_bind_int(stmt, i, val) != SQLITE_OK) { \ + _E("sqlite3_bind_int() is failed. error(%s)", \ + sqlite3_errmsg(db)); \ + sqlite3_finalize(stmt); \ + return -1; \ + } \ +} while (0) + +#define PATH_DB tzplatform_mkpath(TZ_SYS_DB, ".syspopup.db") +#define PATH_DB_JOURNAL tzplatform_mkpath(TZ_SYS_DB, ".syspopup.db-journal") +#define DB_LABEL "User::Home" + +static sqlite3 *__db; + +bool syspopup_parser_db_exist(void) +{ + if (access(PATH_DB, F_OK) == 0) + return true; + + return false; +} + +int syspopup_parser_db_unlink(void) +{ + int ret; + + ret = access(PATH_DB, F_OK); + if (ret == 0) { + ret = unlink(PATH_DB); + if (ret != 0) { + _E("Failed to delete %s. errno(%d)", + PATH_DB, errno); + return -1; + } + } + + return 0; +} + +void syspopup_parser_db_close(void) +{ + if (__db == NULL) + return; + + sqlite3_close(__db); + __db = NULL; +} + +int syspopup_parser_db_open(void) +{ + int ret; + const char *query = CREATE_SYSPOPUP_INFO_TABLE; + char *err_msg = NULL; + + ret = sqlite3_open_v2(PATH_DB, &__db, + SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL); + if (ret != SQLITE_OK) { + _E("Failed to create syspopup db - ret(%d)", ret); + syspopup_parser_db_close(); + return -1; + } + + ret = sqlite3_exec(__db, query, NULL, NULL, &err_msg); + if (ret != SQLITE_OK) { + _E("Failed to create syspopup info table(%s)", err_msg); + sqlite3_free(err_msg); + syspopup_parser_db_close(); + return -1; + } + + ret = smack_setlabel(PATH_DB, DB_LABEL, SMACK_LABEL_ACCESS); + if (ret < 0) { + _E("Failed to set label"); + syspopup_parser_db_close(); + return -1; + } + + if (access(PATH_DB_JOURNAL, F_OK) == 0) { + ret = smack_setlabel(PATH_DB_JOURNAL, DB_LABEL, + SMACK_LABEL_ACCESS); + if (ret < 0) { + _E("Failed to set label of journal file"); + syspopup_parser_db_close(); + return -1; + } + } + + return 0; +} + +int syspopup_parser_db_insert(GList *syspopup_list) +{ + const char *query = QUERY_INSERT_SYSPOPUP_INFO; + sqlite3_stmt *stmt = NULL; + syspopup_t *info; + GList *iter; + int ret; + int idx; + + if (!syspopup_list) { + _E("Invalid parameter"); + return -1; + } + + ret = sqlite3_prepare_v2(__db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _E("sqlite3_prepare_v2() is failed. error(%s)", + sqlite3_errmsg(__db)); + return -1; + } + + iter = syspopup_list; + while (iter) { + info = (syspopup_t *)iter->data; + iter = g_list_next(iter); + if (!info) + continue; + + idx = 1; + BIND_TEXT(__db, stmt, idx++, info->name); + BIND_INT(__db, stmt, idx++, info->priority); + BIND_INT(__db, stmt, idx++, info->focus); + BIND_INT(__db, stmt, idx++, info->timeout); + BIND_INT(__db, stmt, idx++, info->term_action); + BIND_INT(__db, stmt, idx++, info->endkey_action); + BIND_TEXT(__db, stmt, idx++, info->appid); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _E("sqlite3_step() is failed. name[%s] appid[%s]", + info->name, info->appid); + ret = -1; + goto end; + } + + sqlite3_reset(stmt); + + _I("syspopup name[%s] appid[%s] priority[%d] focus[%d] " + "timeout[%d] term-action[%d] endkey-action[%d]", + info->name, info->appid, info->priority, + info->focus, info->timeout, info->term_action, + info->endkey_action); + } + + ret = 0; +end: + sqlite3_finalize(stmt); + + return ret; +} diff --git a/tool/sp_initdb/src/syspopup_type.c b/tool/sp_initdb/src/syspopup_type.c new file mode 100644 index 0000000..7949178 --- /dev/null +++ b/tool/sp_initdb/src/syspopup_type.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> +#include <ctype.h> +#include <unistd.h> +#include <sys/types.h> + +#include "syspopup_private.h" +#include "syspopup_type.h" + +void syspopup_free(syspopup_t *info) +{ + if (!info) + return; + + if (info->name) + free(info->name); + + if (info->appid) + free(info->appid); + + free(info); +} diff --git a/tool/sp_initdb/xml.xsd.in b/tool/sp_initdb/xml.xsd.in new file mode 100644 index 0000000..855c21c --- /dev/null +++ b/tool/sp_initdb/xml.xsd.in @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:packages="http://tizen.org/ns/packages"> + <xs:import namespace="http://tizen.org/ns/packages" schemaLocation="manifest.xsd"/> + <xs:attribute name="lang" type="xs:NCName"/> +</xs:schema> |