From eaf2cc26205bd7c513892e8ae9bbc796e33fb481 Mon Sep 17 00:00:00 2001 From: Kibum Kim Date: Sat, 7 Jan 2012 00:43:27 +0900 Subject: [PATCH] Git init --- AUTHORS | 3 + CMakeLists.txt | 92 +++++ LICENSE | 204 ++++++++++ appsvc.pc.in | 13 + data/appsvc_db.sql | 11 + debian/appsvc-tool.install.in | 1 + debian/changelog | 7 + debian/compat | 1 + debian/control | 31 ++ debian/dirs | 2 + debian/docs | 0 debian/libappsvc-0.install.in | 2 + debian/libappsvc-0.postinst | 18 + debian/libappsvc-dev.install.in | 2 + debian/rules | 114 ++++++ include/appsvc.h | 814 ++++++++++++++++++++++++++++++++++++++++ include/appsvc_db.h | 45 +++ include/internal.h | 60 +++ include/priv_key.h | 43 +++ packaging/app-svc.spec | 68 ++++ src/appsvc.c | 676 +++++++++++++++++++++++++++++++++ src/appsvc_db.c | 239 ++++++++++++ test/CMakeLists.txt | 30 ++ test/a.out | Bin 0 -> 8390 bytes test/appsvc_test.c | 324 ++++++++++++++++ 25 files changed, 2800 insertions(+) create mode 100644 AUTHORS create mode 100755 CMakeLists.txt create mode 100644 LICENSE create mode 100755 appsvc.pc.in create mode 100755 data/appsvc_db.sql create mode 100755 debian/appsvc-tool.install.in create mode 100755 debian/changelog create mode 100644 debian/compat create mode 100755 debian/control create mode 100644 debian/dirs create mode 100644 debian/docs create mode 100755 debian/libappsvc-0.install.in create mode 100755 debian/libappsvc-0.postinst create mode 100755 debian/libappsvc-dev.install.in create mode 100755 debian/rules create mode 100755 include/appsvc.h create mode 100755 include/appsvc_db.h create mode 100755 include/internal.h create mode 100755 include/priv_key.h create mode 100644 packaging/app-svc.spec create mode 100755 src/appsvc.c create mode 100755 src/appsvc_db.c create mode 100755 test/CMakeLists.txt create mode 100755 test/a.out create mode 100755 test/appsvc_test.c diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..064881e --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Jayoun Lee +Sewook Park +Jaeho Lee diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..15fe626 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,92 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + +PROJECT(appsvc C) +SET(VERSION_MAJOR 0) +SET(VERSION "${VERSION_MAJOR}.1.0") + +### Global setting ### + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include/appsvc") + +# Build type : Release +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF() +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + + +# Set required packages +INCLUDE(FindPkgConfig) + +pkg_check_modules(pkgs REQUIRED dlog ecore x11 libprivilege-control aul) +pkg_check_modules(libpkgs REQUIRED dlog bundle dbus-glib-1 ail xdgmime aul glib-2.0) + +FIND_LIBRARY(LIB_DL dl) + +FOREACH(flag ${libpkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(TEST_CFLAGS "${TEST_CFLAGS} ${flag}") +ENDFOREACH(flag) + +# Compiler flags +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/legacy) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +SET(CMAKE_SKIP_BUILD_RPATH true) + +# Get uname value to set 'TARGET' definition +# TODO: Is this needed? +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DRW_DATA_PREFIX=\"/opt/share\"") + +# Linker flags +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + + +### Build ### + + +# aul +add_library(appsvc SHARED + src/appsvc.c + src/appsvc_db.c + ) +target_link_libraries(appsvc ${libpkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(appsvc PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(appsvc PROPERTIES VERSION ${VERSION}) + +# pkgconfig file +CONFIGURE_FILE(appsvc.pc.in appsvc.pc @ONLY) + + +### Install ### +INSTALL(TARGETS appsvc DESTINATION lib COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${AVATAR_NAME} DESTINATION bin) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/appsvc.h DESTINATION include/appsvc) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/appsvc.pc DESTINATION lib/pkgconfig) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/appsvc_db.sql DESTINATION /opt/share ) + +# test +add_subdirectory(test) + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9c13a9b --- /dev/null +++ b/LICENSE @@ -0,0 +1,204 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + diff --git a/appsvc.pc.in b/appsvc.pc.in new file mode 100755 index 0000000..4037bbb --- /dev/null +++ b/appsvc.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=/usr +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: libaul +Description: new application utility library +Version: @VERSION@ +Requires: sqlite3 bundle ail glib-2.0 xdgmime aul +Libs: -L${libdir} -lappsvc +Cflags: -I${includedir} diff --git a/data/appsvc_db.sql b/data/appsvc_db.sql new file mode 100755 index 0000000..290feee --- /dev/null +++ b/data/appsvc_db.sql @@ -0,0 +1,11 @@ +PRAGMA journal_mode = PERSIST; + +CREATE TABLE IF NOT EXISTS appsvc ( + operation TEXT, + mime_type TEXT DEFAULT 'NULL', + uri TEXT DEFAULT 'NULL', + pkg_name TEXT, + PRIMARY KEY (operation,mime_type,uri) +); + + diff --git a/debian/appsvc-tool.install.in b/debian/appsvc-tool.install.in new file mode 100755 index 0000000..6ee69bd --- /dev/null +++ b/debian/appsvc-tool.install.in @@ -0,0 +1 @@ +@PREFIX@/bin/appsvc_test diff --git a/debian/changelog b/debian/changelog new file mode 100755 index 0000000..39995a7 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,7 @@ +app-svc (0.1.18-2) unstable; urgency=low + + * Initial release + * Git: pkgs/a/app-svc + * Tag: app-svc_0.1.18-2 + + -- Jaeho lee Wed, 07 Dec 2011 14:02:52 +0900 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..99abe21 --- /dev/null +++ b/debian/control @@ -0,0 +1,31 @@ +Source: app-svc +Section: devel +Priority: extra +Maintainer: Jayoun Lee , Sewook Park , Jaeho Lee +Build-Depends: debhelper (>= 5), libdbus-glib-1-dev, libsqlite3-dev, libx11-dev, libecore-dev, libbundle-dev, libail-0-dev, dlog-dev, libxdgmime-dev, libprivilege-control-dev, sqlite3, libaul-1-dev +Standards-Version: 0.1.0 + +Package: libappsvc-dev +Section: libs +Architecture: any +Depends: libappsvc-0 (= ${Source-Version}), libaul-1, libdbus-glib-1-dev, libsqlite3-dev, libbundle-dev, libail-0-dev, dlog-dev, libxdgmime-dev, sqlite3, libaul-1-dev +Description: libappsvc dev package + +Package: libappsvc-0 +Section: libs +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, sqlite3 +Description: libappsvc-0 package + +Package: libappsvc-dbg +Section: debug +Architecture: any +Depends: libappsvc-0 (= ${Source-Version}), ${shlibs:Depends}, ${misc:Depends} +Description: libappsvc dbg package + +Package: appsvc-tool +Section: libs +Architecture: any +Depends: libappsvc-0 (= ${Source-Version}), ${shlibs:Depends}, ${misc:Depends} +Description: libappsvc-0 executable package (appsvc_test) + diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..ca882bb --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/bin +usr/sbin diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e69de29 diff --git a/debian/libappsvc-0.install.in b/debian/libappsvc-0.install.in new file mode 100755 index 0000000..83f97d6 --- /dev/null +++ b/debian/libappsvc-0.install.in @@ -0,0 +1,2 @@ +@PREFIX@/lib/libappsvc.* +/opt/share/* diff --git a/debian/libappsvc-0.postinst b/debian/libappsvc-0.postinst new file mode 100755 index 0000000..31e162c --- /dev/null +++ b/debian/libappsvc-0.postinst @@ -0,0 +1,18 @@ +#!/bin/sh + +mkdir -p /opt/dbspace +sqlite3 /opt/dbspace/.appsvc.db < /opt/share/appsvc_db.sql +rm -rf /opt/share/appsvc_db.sql + +if [ "${USER}" = "root" ] +then + chown root:root /usr/lib/libappsvc.so.0.1.0 + chown root:5000 /opt/dbspace/.appsvc.db + chown root:5000 /opt/dbspace/.appsvc.db-journal +fi + +chmod 644 /usr/lib/libappsvc.so.0.1.0 +chmod 664 /opt/dbspace/.appsvc.db +chmod 664 /opt/dbspace/.appsvc.db-journal + +#chmod 1777 /opt/share/miregex # Set directory to be writable for other accounts diff --git a/debian/libappsvc-dev.install.in b/debian/libappsvc-dev.install.in new file mode 100755 index 0000000..0f2a4da --- /dev/null +++ b/debian/libappsvc-dev.install.in @@ -0,0 +1,2 @@ +@PREFIX@/include/* +@PREFIX@/lib/pkgconfig/*.pc diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..ac9fca7 --- /dev/null +++ b/debian/rules @@ -0,0 +1,114 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + +CFLAGS += -Wall -g +LDFLAGS ?= +PREFIX ?= /usr +DATADIR ?= /opt + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +CFLAGS += -fvisibility=hidden -fpic +LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed + +CMAKE_TMP_DIR = $(CURDIR)/cmake_tmp + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + mkdir -p $(CMAKE_TMP_DIR); + cd $(CMAKE_TMP_DIR); CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX) + + touch configure-stamp + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + cd $(CMAKE_TMP_DIR) && $(MAKE) all test + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + cat $$f > $${f%.in}; \ + sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ + sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ + done + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + rm -rf $(CMAKE_TMP_DIR) + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + rm -f $${f%.in}; \ + done + + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/wavplayer. + cd $(CMAKE_TMP_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip --dbg-package=libappsvc-dbg + dh_compress + dh_fixperms +# dh_perl + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/include/appsvc.h b/include/appsvc.h new file mode 100755 index 0000000..a3bc249 --- /dev/null +++ b/include/appsvc.h @@ -0,0 +1,814 @@ +/* + * app-svc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * 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 __APP_SVC_H__ +#define __APP_SVC_H__ + +/** + * @file appsvc.h + * @version 1.1 + * @brief This file contains APIs of the appsvc library + */ + +/** + * @addtogroup APPLICATION_FRAMEWORK + * @{ + * + * @defgroup appsvc Application Service + * @version 1.1 + * @brief Application Service library + * + */ + +/** + * @addtogroup appsvc + * @{ + */ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_DEFAULT "slp.appsvc.operation.DEFAULT" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_EDIT "slp.appsvc.operation.EDIT" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_VIEW "slp.appsvc.operation.VIEW" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_PICK "slp.appsvc.operation.PICK" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_CREATE_CONTENT "slp.appsvc.operation.CREATE_CONTENT" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_CALL "slp.appsvc.operation.CALL" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_SEND "slp.appsvc.operation.SEND" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_SEND_TEXT "slp.appsvc.operation.SEND_TEXT" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_DIAL "slp.appsvc.operation.DIAL" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_SEARCH "slp.appsvc.operation.SEARCH" +/** APP_SVC OPERATION TYPE*/ +#define APPSVC_OPERATION_DOWNLOAD "slp.appsvc.operation.DOWNLOAD" + + +/** APP_SVC DATA SUBJECT*/ +#define APPSVC_DATA_SUBJECT "slp.appsvc.data.SUBJECT" +/** APP_SVC DATA TYPE*/ +#define APPSVC_DATA_TO "slp.appsvc.data.TO" +/** APP_SVC DATA TYPE*/ +#define APPSVC_DATA_CC "slp.appsvc.data.CC" +/** APP_SVC DATA TYPE*/ +#define APPSVC_DATA_BCC "slp.appsvc.data.BCC" +/** APP_SVC DATA TYPE*/ +#define APPSVC_DATA_TEXT "slp.appsvc.data.TEXT" +/** APP_SVC DATA TYPE*/ +#define APPSVC_DATA_TITLE "slp.appsvc.data.TITLE" +/** APP_SVC DATA TYPE*/ +#define APPSVC_DATA_SELECTED "slp.appsvc.data.SELECTED" +/** APP_SVC DATA TYPE*/ +#define APPSVC_DATA_KEYWORD "slp.appsvc.data.KEYWORD" + + +/** + * @brief Return values in appsvc. + */ +typedef enum _appsvc_return_val { + APPSVC_RET_ELAUNCH = -4, /**< Failure on launching the app */ + APPSVC_RET_ENOMATCH = -3, /**< No matching result Error */ + APPSVC_RET_EINVAL = -2, /**< Invalid argument */ + APPSVC_RET_ERROR = -1, /**< General error */ + APPSVC_RET_OK = 0 /**< General success */ +}appsvc_return_val; + + +/** + * @brief result values in appsvc. + */ +typedef enum _appsvc_result_val { + APPSVC_RES_CANCEL = -2, /**< Cancel by system */ + APPSVC_RES_NOT_OK = -1, /**< Fail by user */ + APPSVC_RES_OK = 0 /**< Success by user */ +}appsvc_result_val; + + +/** + * @brief appsvc_res_fn is appsvc result function + * @param[out] b result bundle + * @param[out] request_code request code + * @param[out] result result value + * @param[out] data user-supplied data +*/ +typedef void (*appsvc_res_fn)(bundle *b, int request_code, appsvc_result_val result, void *data); + + +/** + * @brief iterator function running with appsvc_get_list + * @param[out] pkg_name package name retreived by appsvc_get_list + * @param[out] data user-supplied data +*/ +typedef int (*appsvc_info_iter_fn)(const char *pkg_name, void *data); + + +/** + * @par Description: + * This function sets an operation to launch application based on appsvc. + * + * @param[in] b bundle object + * @param[in] operation operation + * + * @return 0 if success, negative value(<0) if fail + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * + * @pre None. + * @post None. + * @see None. + * @remarks An application must call this function before using appsvc_run_service API. + * + * @par Sample code: + * @code +#include + +... +{ + bundle *b = NULL; + + b = bundle_create(); + + appsvc_set_operation(b, APPSVC_OPERATION_VIEW); +} + * @endcode + * + */ +int appsvc_set_operation(bundle *b, const char *operation); + +/** + * @par Description: + * This function sets an uri to launch application based on appsvc. + * + * @param[in] b bundle object + * @param[in] uri uri + * + * @return 0 if success, negative value(<0) if fail + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + bundle *b = NULL; + + b = bundle_create(); + + appsvc_set_operation(b, APPSVC_OPERATION_VIEW); + appsvc_set_uri(b,"http://www.samsung.com"); +} + * @endcode + * + */ +int appsvc_set_uri(bundle *b, const char *uri); + +/** + * @par Description: + * This function sets a mime-type to launch application based on appsvc. + * + * @param[in] b bundle object + * @param[in] mime mime-type + * + * @return 0 if success, negative value(<0) if fail + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + bundle *b = NULL; + + b = bundle_create(); + + appsvc_set_operation(b, APPSVC_OPERATION_PICK); + appsvc_set_mime(b,"image/jpg"); +} + * @endcode + * + */ +int appsvc_set_mime(bundle *b, const char *mime); + +/** + * @par Description: + * This function sets an extra data to launch application based on appsvc. + * + * @param[in] b bundle object + * @param[in] key key of extra data + * @param[in] val data + * + * @return 0 if success, negative value(<0) if fail + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + bundle *b = NULL; + + b = bundle_create(); + + appsvc_set_operation(b, APPSVC_OPERATION_SEND); + appsvc_set_uri(b,"mailto:xxx1@xxx"); + appsvc_add_data(b,APPSVC_DATA_CC,"xxx2@xxx"); +} + * @endcode + * + */ +int appsvc_add_data(bundle *b, const char *key, const char *val); + +/** + * @par Description: + * This function sets an extra array data to launch application based on appsvc. + * + * @param[in] b bundle object + * @param[in] key key of extra data + * @param[in] val_array data + * @param[in] len Length of array + * + * @return 0 if success, negative value(<0) if fail + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + bundle *b = NULL; + char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"}; + + b = bundle_create(); + + appsvc_add_data_array(b, APPSVC_DATA_SELECTED, images, 3); +} + * @endcode + * + */ +int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len); + + +/** + * @par Description: + * This function sets a package name to launch application based on appsvc. + * + * @param[in] b bundle object + * @param[in] pkg_name package name for explict launch + * + * @return 0 if success, negative value(<0) if fail + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + bundle *b = NULL; + + b = bundle_create(); + + appsvc_set_operation(b, APPSVC_OPERATION_PICK); + appsvc_set_mime(b,"image/jpg"); + appsvc_set_pkgname(b, "org.tizen.mygallery"); +} + * @endcode + * + */ +int appsvc_set_pkgname(bundle *b, const char *pkg_name); + +/** + * @par Description: + * This API launch application based on appsvc. + * + * @param[in] b bundle to be passed to callee + * @param[in] request_code request code + * @param[in] cbfunc result callback function + * @param[in] data user-supplied data passed to callback function + * + * @return callee's pid if success, negative value(<0) if fail + * @retval callee's pid - success + * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * @retval APPSVC_RET_ENOMATCH - no matching result Error + * @retval APPSVC_RET_ELAUNCH - failure on launching the app + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + bundle *b = NULL; + static int num = 0; + + b = bundle_create(); + + appsvc_set_operation(b, APPSVC_OPERATION_PICK); + appsvc_set_mime(b,"image/jpg"); + + return appsvc_run_service(b, 0, cb_func, (void*)NULL); +} + * @endcode + * + */ +int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data); + +/** + * @par Description: + * This API use to get application list that is matched with given bundle. + * + * @param[in] b bundle to resolve application + * @param[in] iter_fn iterator function + * @param[in] data user-supplied data for iter_fn + * + * @return 0 if success, negative value(<0) if fail + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * @retval APPSVC_RET_ENOMATCH - no matching result Error + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +static int iter_fn(const char* pkg_name, void *data) +{ + printf("\t==========================\n"); + printf("\t pkg_name: %s\n", pkg_name); + printf("\t==========================\n"); + return 0; +} + +... +{ + bundle *b = NULL; + static int num = 0; + + b = bundle_create(); + + appsvc_set_operation(b, APPSVC_OPERATION_PICK); + appsvc_set_mime(b,"image/jpg"); + + return appsvc_get_list(b, iter_fn, (void*)NULL); +} + * @endcode + * + */ +int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data); + +/** + * @par Description: + * This function gets a operation from bundle. + * + * @param[in] b bundle object + * + * @return Pointer for operation string if success, NULL if fail + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + char *val; + val = appsvc_get_operation(b); +} + * @endcode + * + */ +const char *appsvc_get_operation(bundle *b); + +/** + * @par Description: + * This function gets a uri from bundle. + * + * @param[in] b bundle object + * + * @return Pointer for uri string if success, NULL if fail + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + char *val; + val = appsvc_get_uri(b); +} + * @endcode + * + */ +const char *appsvc_get_uri(bundle *b); + +/** + * @par Description: + * This function gets a mime-type from bundle. + * + * @param[in] b bundle object + * + * @return Pointer for mime-type string if success, NULL if fail + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + char *val; + val = appsvc_get_mime(b); +} + * @endcode + * + */ +const char *appsvc_get_mime(bundle *b); + +/** + * @par Description: + * This function gets a package name from bundle. + * + * @param[in] b bundle object + * + * @return Pointer for package name string if success, NULL if fail + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + char *val; + val = appsvc_get_pkgname(b); +} + * @endcode + * + */ +const char *appsvc_get_pkgname(bundle *b); + +/** + * @par Description: + * This function gets value from key. + * + * @param[in] b bundle object + * @param[in] key key + * + * @return Pointer for value string if success, NULL if fail + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + char *val; + val = appsvc_get_data(b, APPSVC_DATA_CC); +} + * @endcode + * + */ +const char *appsvc_get_data(bundle *b, const char *key); + +/** + * @par Description: + * This function gets value from key. + * + * @param[in] b bundle object + * @param[in] key key + * @param[out] len length of array + * + * @return Pointer for value string array if success, NULL if fail + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + char **val_array; + int len; + char *val; + + if(appsvc_data_is_array(b, APPSVC_DATA_SELECTED)) + val_array = appsvc_get_data_array(b, APPSVC_DATA_SELECTED, &len); + else + val = appsvc_get_data(b, APPSVC_DATA_SELECTED); +} + * @endcode + * + */ +const char **appsvc_get_data_array(bundle *b, const char *key, int *len); + +/** + * @par Description: + * This API create appsvc result bundle based on bundle received in reset event. + * + * @param[in] inb bundle received in reset event + * @param[in] outb bundle to use for returning result + * + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * + * @pre None. + * @post None. + * @see appsvc_send_result. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + struct appdata *ad = data; + bundle* res_bundle; + + appsvc_create_result_bundle(ad->b,&res_bundle); + bundle_add(res_bundle, "result", "1"); + appsvc_send_result(res_bundle, 0); +} + * @endcode + * + */ +int appsvc_create_result_bundle(bundle *inb, bundle **outb); + +/** + * @par Description: + * This API send appsvc result to caller with bundle. + * + * @param[in] b Result data in bundle format + * @param[in] result result value + * + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * + * @pre appsvc_create_result_bundle. + * @post None. + * @see appsvc_send_result. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + struct appdata *ad = data; + bundle* res_bundle; + + appsvc_create_result_bundle(ad->b,&res_bundle); + bundle_add(res_bundle, "result", "1"); + appsvc_send_result(res_bundle, 0); +} + * @endcode + * + */ +int appsvc_send_result(bundle *b, appsvc_result_val result); + +/** + * @par Description: + * This API set the default application(package name) associated with op, uri and mime-type. + * + * @param[in] op operation + * @param[in] mime_type mime-type + * @param[in] scheme scheme of uri + * @param[in] defapp default application + * + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + appsvc_set_defapp(APPSVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser"); +} + * @endcode + * + */ +int appsvc_set_defapp(const char *op,const char *mime_type,const char *scheme,const char *defapp); + +/** + * @par Description: + * This API unset the default application(package name) associated with op, uri and mime-type. + * + * @param[in] defapp default application + * + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + appsvc_unset_defapp("org.tizen.test"); +} + * @endcode + * + */ +int appsvc_unset_defapp(const char *defapp); + +/** + * @par Description: + * This API ask a application is default application or not. + * + * @param[in] pkg_name application package name + * @return true / false + * @retval 1 app_name is default application in appsvc. + * @retval 0 app_name is NOT default application in appsvc. + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + + ... + + * int is_defapp_browser_app() + * { + * return appsvc_is_defapp("org.tizen.browser"); + * } + * + * @endcode + * @remark + * None +* +*/ +int appsvc_is_defapp(const char *pkg_name); + + +/** + * @par Description: + * This API ask a extra data is array or not. + * + * @param[in] b bundle object + * @param[in] key key of extra data + * @return true / false + * @retval 1 a extra data is array. + * @retval 0 a extra data is not array. + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + + ... + + * int is_defapp_browser_app(bundle *b, char *key) + * { + * return appsvc_data_is_array(b, key); + * } + * + * @endcode + * @remark + * None +* +*/ +int appsvc_data_is_array(bundle *b, const char *key); + + +#ifdef __cplusplus + } +#endif + +/** + * @} + */ +/** + * @} + */ + + +#endif /* __APP_SVC_H__ */ + +/* vi: set ts=8 sts=8 sw=8: */ diff --git a/include/appsvc_db.h b/include/appsvc_db.h new file mode 100755 index 0000000..d1dd899 --- /dev/null +++ b/include/appsvc_db.h @@ -0,0 +1,45 @@ +/* + * app-svc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * 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 __APP_SVC_DB_H__ +#define __APP_SVC_DB_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, const char *pkg_name); +int _svc_db_delete_with_pkgname(const char *pkg_name); +char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri); + +#ifdef __cplusplus +} +#endif + +#endif /* __APP_SVC_DB_H__ */ + diff --git a/include/internal.h b/include/internal.h new file mode 100755 index 0000000..0e42b81 --- /dev/null +++ b/include/internal.h @@ -0,0 +1,60 @@ +/* + * app-svc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * 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 __INTERNAL_H__ +#define __INTERNAL_H__ + +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "APPSVC" + +#define MAX_FILTER_STR_SIZE 1024 +#define MAX_PACKAGE_STR_SIZE 512 +#define MAX_URI_STR_SIZE 256 +#define MAX_MIME_STR_SIZE 256 +#define MAX_SCHEME_STR_SIZE 256 +#define MAX_OP_STR_SIZE 128 +#define MAX_LOCAL_BUFSZ 128 + +#define _E(fmt, arg...) LOGE("[%s,%d] "fmt,__FUNCTION__,__LINE__,##arg) +#define _D(fmt, arg...) LOGD("[%s,%d] "fmt,__FUNCTION__,__LINE__,##arg) + +#define retvm_if(expr, val, fmt, arg...) do { \ + if(expr) { \ + _E(fmt, ##arg); \ + _E("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ +} while (0) + +#define retv_if(expr, val) do { \ + if(expr) { \ + _E("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ +} while (0) + +#endif /* __INTERNAL_H__ */ + diff --git a/include/priv_key.h b/include/priv_key.h new file mode 100755 index 0000000..daac8a7 --- /dev/null +++ b/include/priv_key.h @@ -0,0 +1,43 @@ +/* + * app-svc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * 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 __PRIV_KEY_H__ +#define __PRIV_KEY_H__ + + +/** APP SVC internal private key */ +#define APP_SVC_K_OPERATION "__APP_SVC_OP_TYPE__" +/** APP SVC internal private key */ +#define APP_SVC_K_URI "__APP_SVC_URI__" +/** APP SVC internal private key */ +#define APP_SVC_K_MIME "__APP_SVC_MIME_TYPE__" +/** APP SVC internal private key */ +#define APP_SVC_K_DATA "__APP_SVC_DATA__" +/** APP SVC internal private key */ +#define APP_SVC_K_PKG_NAME "__APP_SVC_PKG_NAME__" +/** APP SVC internal private key */ +#define APP_SVC_K_RES_VAL "__APP_SVC_K_RES_VAL__" + + +#endif /* __PRIV_KEY_H__ */ + +/* vi: set ts=8 sts=8 sw=8: */ diff --git a/packaging/app-svc.spec b/packaging/app-svc.spec new file mode 100644 index 0000000..38a0799 --- /dev/null +++ b/packaging/app-svc.spec @@ -0,0 +1,68 @@ +Name: app-svc +Summary: App svc +Version: 0.1.4 +Release: 1 +Group: System/Libraries +License: SAMSUNG +Source0: %{name}-%{version}.tar.gz + +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + + +BuildRequires: cmake + +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(ecore) +BuildRequires: pkgconfig(x11) +BuildRequires: pkgconfig(libprivilege-control) +BuildRequires: pkgconfig(bundle) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(ail) +BuildRequires: pkgconfig(xdgmime) +BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(glib-2.0) + + +%description +App svc + +%package devel +Summary: App svc +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +%description devel +App svc (developement files) + +%prep +%setup -q + + +%build + +CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" cmake . -DCMAKE_INSTALL_PREFIX=/usr + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%defattr(-,root,root,-) +/opt/share/appsvc_db.sql +/usr/bin/appsvc_test +/usr/lib/libappsvc.so.0 +/usr/lib/libappsvc.so.0.1.0 + +%files devel +%defattr(-,root,root,-) +/usr/lib/pkgconfig/appsvc.pc +/usr/lib/libappsvc.so +/usr/include/appsvc/appsvc.h diff --git a/src/appsvc.c b/src/appsvc.c new file mode 100755 index 0000000..0adcdca --- /dev/null +++ b/src/appsvc.c @@ -0,0 +1,676 @@ +/* + * app-svc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * 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. + * + */ + + +#include +#include +#include +#include + +#include +#include + +#include "appsvc.h" +#include "appsvc_db.h" +#include "internal.h" +#include "priv_key.h" + + + + +#define APP_SELECTOR "org.tizen.app-selector" + +#ifndef SLPAPI +#define SLPAPI __attribute__ ((visibility("default"))) +#endif + + +/* callback handling */ +typedef struct _appsvc_cb_info_t{ + appsvc_res_fn cb_func; + int request_code; + void *data; +}appsvc_cb_info_t; + +typedef struct _appsvc_resolve_info_t{ + char *pkgname; + char *op; + char *uri; + char *scheme; + char *origin_mime; + char *mime; + char *m_type; + char *s_type; + int mime_set; +}appsvc_resolve_info_t; + +static appsvc_cb_info_t *__create_rescb(int request_code, appsvc_res_fn cbfunc, + void *data); +static void __remove_rescb(appsvc_cb_info_t *info); +static void __bundle_iterate(const char *key, const char *val, void *data); +static int __set_bundle(bundle *b, const char *key, const char *value); +static void __aul_cb(bundle *b, int is_cancel, void *data); +static int __svc_iter_func(const char* pkg_name, void *data); +static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, + appsvc_res_fn cbfunc, void *data); +static int __get_resolve_info(bundle *b, appsvc_resolve_info_t *info); +static int __free_resolve_info_data(appsvc_resolve_info_t *info); +static ail_cb_ret_e __ail_iter_func(const ail_appinfo_h appinfo, + void *user_data); +static int __get_list_with_condition(char *op, char *scheme, + char *mime, GSList **pkg_list); + + +static appsvc_cb_info_t *__create_rescb(int request_code, appsvc_res_fn cbfunc, void *data) +{ + appsvc_cb_info_t* info; + + info = (appsvc_cb_info_t*)calloc(1, sizeof(appsvc_cb_info_t)); + if(info == NULL) + return NULL; + + info->request_code = request_code; + info->cb_func = cbfunc; + info->data = data; + + return info; +} + +static void __remove_rescb(appsvc_cb_info_t *info) +{ + if(info) free(info); +} + +static void __bundle_iterate(const char *key, const char *val, void *data) +{ + static int i=0; + _D("%d %s %s", i++, key, val); +} + +static int __set_bundle(bundle *b, const char *key, const char *value) +{ + char *val = bundle_get_val(b, key); + if(val){ + if( bundle_del(b, key) != 0 ){ + return APPSVC_RET_ERROR; + } + } + + if(!value) + return APPSVC_RET_EINVAL; + + if( bundle_add(b, key, value) != 0 ){ + return APPSVC_RET_ERROR; + } + + _D("__set_bundle"); +// bundle_iterate(b, __bundle_iterate, NULL); + + return APPSVC_RET_OK; +} + +static int __set_bundle_array(bundle *b, const char *key, const char **value, int len) +{ + + int type; + type = appsvc_data_is_array(b, key); + + if(type == 1) { + if( bundle_del(b, key) != 0 ){ + return APPSVC_RET_ERROR; + } + } + + if(!value) + return APPSVC_RET_EINVAL; + + if( bundle_add_str_array(b, key, value, len) != 0 ){ + return APPSVC_RET_ERROR; + } + + _D("__set_bundle_array"); +// bundle_iterate(b, __bundle_iterate, NULL); + + return APPSVC_RET_OK; +} + + +static void __aul_cb(bundle *b, int is_cancel, void *data) +{ + char *val; + appsvc_cb_info_t* cb_info; + int res; + + if(is_cancel) + res = APPSVC_RES_CANCEL; + else{ + /* get result_code from bundle */ + val = bundle_get_val(b, APP_SVC_K_RES_VAL); + res = (val==NULL)? APPSVC_RES_NOT_OK : atoi(val); + } + + /* remove result_code from bundle */ + bundle_del(b, APP_SVC_K_RES_VAL); + + /* find corresponding callback */ + cb_info = (appsvc_cb_info_t*)data; + + cb_info->cb_func(b, cb_info->request_code, (appsvc_result_val)res, cb_info->data); + __remove_rescb(cb_info); + + + return; +} + +static int __svc_iter_func(const char* pkg_name, void *data) +{ + GSList **pkg_list = (GSList **)data; + char *pkgname = NULL; + + pkgname = strdup(pkg_name); + + *pkg_list = g_slist_append(*pkg_list, pkgname); + + return 0; +} + +static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, appsvc_res_fn cbfunc, void *data) +{ + appsvc_cb_info_t *cb_info = NULL; + int ret = -1; + + if (cbfunc) { + _D("pkg_name : %s - with result", pkgname); + + cb_info = __create_rescb(request_code, cbfunc, data); + ret = aul_launch_app_with_result(pkgname, b, __aul_cb, cb_info); + if(ret < 0) + ret = APPSVC_RET_ELAUNCH; + } else { + _D("pkg_name : %s - no result", pkgname); + ret = aul_launch_app(pkgname, b); + if(ret < 0) + ret = APPSVC_RET_ELAUNCH; + } + + return ret; +} + +static int __get_resolve_info(bundle *b, appsvc_resolve_info_t *info) +{ + char *tmp = NULL; + char *tmp2 = NULL; + char *strtok_buf = NULL; + + info->op = appsvc_get_operation(b); + info->uri = appsvc_get_uri(b); + info->origin_mime = info->mime = appsvc_get_mime(b); + info->pkgname = appsvc_get_pkgname(b); + + if(info->uri) { + if(strncmp(info->uri,"/",1) == 0){ + if(!info->mime) { + info->mime = malloc(MAX_MIME_STR_SIZE); + aul_get_mime_from_file(info->uri, info->mime, MAX_MIME_STR_SIZE); + info->mime_set = 1; + } + info->uri = NULL; + } else if(strncmp(info->uri,"file:/",6)==0){ + if(!info->mime) { + info->mime = malloc(MAX_MIME_STR_SIZE); + aul_get_mime_from_file(&info->uri[5], info->mime, MAX_MIME_STR_SIZE); + info->mime_set = 1; + } + info->uri = NULL; + } else if(strncmp(info->uri,"file:///",8) == 0){ + if(!info->mime) { + info->mime = malloc(MAX_MIME_STR_SIZE); + aul_get_mime_from_file(&info->uri[7], info->mime, MAX_MIME_STR_SIZE); + info->mime_set = 1; + } + info->uri = NULL; + } + } + + if(info->uri) { + info->scheme = malloc(MAX_SCHEME_STR_SIZE); + tmp = strdup(info->uri); + tmp2 = strtok(tmp,":"); + if(tmp2) + strncpy(info->scheme, tmp2, MAX_SCHEME_STR_SIZE-1); + free(tmp); + } else { + info->scheme = strdup("NULL"); + } + + if(!info->mime) + info->mime = strdup("NULL"); + else { + info->m_type = malloc(MAX_LOCAL_BUFSZ); + info->s_type = malloc(MAX_LOCAL_BUFSZ); + tmp = strdup(info->mime); + strtok_buf = strtok(tmp,"/"); + if(strtok_buf) + strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ-1); + strtok_buf = strtok(NULL,"/"); + if(strtok_buf) + strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ-1); + free(tmp); + + if(strncmp(info->m_type, "*", 1) == 0) { + strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ-1); + } + if(strncmp(info->s_type, "*", 1) == 0) { + strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ-1); + } + + if(!info->mime_set) info->mime = malloc(MAX_MIME_STR_SIZE); + snprintf(info->mime, MAX_MIME_STR_SIZE-1, "%s/%s", info->m_type, info->s_type); + } + + return 0; +} + +static int __free_resolve_info_data(appsvc_resolve_info_t *info) +{ + if (info->mime) + free(info->mime); + if (info->scheme) + free(info->scheme); + if (info->m_type) + free(info->m_type); + if (info->s_type) + free(info->s_type); + + return 0; +} + +static ail_cb_ret_e __ail_iter_func( + const ail_appinfo_h appinfo, void *user_data) +{ + GSList **pkg_list = (GSList **)user_data; + GSList *iter = NULL; + char *str = NULL; + char *pkgname = NULL; + + ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &str); + + _D("Matching application is %s",str); + + for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) { + pkgname = (char *)iter->data; + if (strncmp(str, pkgname, MAX_PACKAGE_STR_SIZE-1) == 0) + return AIL_CB_RET_CONTINUE; + } + + pkgname = strdup(str); + *pkg_list = g_slist_append(*pkg_list, (void *)pkgname); + _D("%s is added",pkgname); + + return AIL_CB_RET_CONTINUE; +} + +static int __get_list_with_condition(char *op, char *scheme, char *mime, GSList **pkg_list) +{ + ail_filter_h filter; + ail_error_e ail_ret; + char svc_filter[MAX_FILTER_STR_SIZE] = {0,}; + + ail_ret = ail_filter_new(&filter); + if (ail_ret != AIL_ERROR_OK) + return APPSVC_RET_ERROR; + + snprintf(svc_filter, MAX_FILTER_STR_SIZE-1, "%s:%s:%s", op, scheme, mime); + _D("svc_filter : %s",svc_filter); + + ail_ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_SVC_STR, svc_filter); + if (ail_ret != AIL_ERROR_OK) { + ail_filter_destroy(filter); + return APPSVC_RET_ERROR; + } + + ail_filter_list_appinfo_foreach(filter, __ail_iter_func, (void *)pkg_list); + + ail_filter_destroy(filter); + + return APPSVC_RET_OK; +} + +SLPAPI int appsvc_set_operation(bundle *b, const char *operation) +{ + if(b == NULL){ + _E("bundle for appsvc_set_operation is NULL"); + return APPSVC_RET_EINVAL; + } + + return __set_bundle(b, APP_SVC_K_OPERATION, operation); +} + +SLPAPI int appsvc_set_uri(bundle *b, const char *uri) +{ + if(b == NULL){ + _E("bundle for appsvc_set_uri is NULL"); + return APPSVC_RET_EINVAL; + } + + return __set_bundle(b, APP_SVC_K_URI, uri); +} + +SLPAPI int appsvc_set_mime(bundle *b, const char *mime) +{ + if(b == NULL){ + _E("bundle for appsvc_set_mime is NULL"); + return APPSVC_RET_EINVAL; + } + + return __set_bundle(b, APP_SVC_K_MIME, mime); +} + +SLPAPI int appsvc_add_data(bundle *b, const char *key, const char *val) +{ + if(b == NULL || key == NULL) { + return APPSVC_RET_EINVAL; + } + + /* check key for data */ + /******************/ + + return __set_bundle(b, key, val); +} + +SLPAPI int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len) +{ + if(b == NULL || key == NULL) { + return APPSVC_RET_EINVAL; + } + + /* check key for data */ + /******************/ + + return __set_bundle_array(b, key, val_array, len); +} + + +SLPAPI int appsvc_set_pkgname(bundle *b, const char *pkg_name) +{ + if(b == NULL){ + _E("bundle for appsvc_set_pkgname is NULL"); + return APPSVC_RET_EINVAL; + } + + return __set_bundle(b, APP_SVC_K_PKG_NAME, pkg_name); +} + +SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data) +{ + appsvc_resolve_info_t info; + char *pkgname; + int pkg_count = 0; + int ret = -1; + + int mime_set = 0; + + GSList *pkg_list = NULL; + GSList *iter = NULL; + char *list_item; + + if(b == NULL){ + _E("bundle for appsvc_set_pkgname is NULL"); + return APPSVC_RET_EINVAL; + } + + memset(&info, 0, sizeof(appsvc_resolve_info_t)); + __get_resolve_info(b, &info); + + pkgname = info.pkgname; + _D("op - %s / mime - %s / shceme - %s\n", info.op, info.mime, info.scheme); + + /* explict*/ + if(pkgname) { + if(appsvc_get_operation(b) == NULL) + appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT); + ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); + if (info.mime_set) appsvc_set_mime(b,NULL); + __free_resolve_info_data(&info); + return ret; + } + + pkgname = _svc_db_get_app(info.op, info.origin_mime, info.scheme); + + if(pkgname==NULL){ + appsvc_get_list(b, __svc_iter_func, (void *)&pkg_list); + + pkg_count = g_slist_length(pkg_list); + if(pkg_count == 1){ + pkgname = (char *)pkg_list->data; + if(pkgname != NULL){ + ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); + } + } + else if(pkg_count < 1){ + if (info.mime_set) appsvc_set_mime(b,NULL); + return APPSVC_RET_ENOMATCH; + } else { + ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data); + } + + for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { + list_item = (char *)iter->data; + g_free(list_item); + } + g_slist_free(pkg_list); + } else { + ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); + } + if (info.mime_set) appsvc_set_mime(b,NULL); + + __free_resolve_info_data(&info); + return ret; +} + +SLPAPI int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data) +{ + appsvc_resolve_info_t info; + char *pkgname = NULL; + int pkg_count; + + GSList *pkg_list = NULL; + GSList *iter = NULL; + + if(b == NULL){ + _E("bundle for appsvc_run_service is NULL"); + return APPSVC_RET_EINVAL; + } + + if (iter_fn == NULL){ + _E("iter_fn for appsvc_run_service is NULL"); + return APPSVC_RET_EINVAL; + } + + /* parse bundle */ + memset(&info, 0, sizeof(appsvc_resolve_info_t)); + __get_resolve_info(b,&info); + + _D("operation - %s / shceme - %s / mime - %s\n", info.op, info.scheme, info.mime); + __get_list_with_condition(info.op, info.scheme,info.mime, &pkg_list); + + if ((strncmp(info.mime, "NULL", 4) != 0) && (strncmp(info.s_type, "%", 1) != 0)) { + snprintf(info.mime, MAX_MIME_STR_SIZE-1, "%s/*", info.m_type); + __get_list_with_condition(info.op, info.scheme, info.mime, &pkg_list); + } + + if ((strncmp(info.mime, "NULL", 4) != 0) && (strncmp(info.m_type, "%", 1) != 0)) { + snprintf(info.mime, MAX_MIME_STR_SIZE-1, "*/*"); + __get_list_with_condition(info.op, info.scheme, info.mime, &pkg_list); + } + + pkg_count = g_slist_length(pkg_list); + if (pkg_count == 0) { + _E("Cannot find associated application"); + return APPSVC_RET_ENOMATCH; + } + + for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { + pkgname = iter->data; + _D("PKGNAME : %s\n", pkgname); + if( iter_fn(pkgname,data) != 0) + break; + g_free(pkgname); + } + + g_slist_free(pkg_list); + __free_resolve_info_data(&info); + + return APPSVC_RET_OK; +} + +SLPAPI const char *appsvc_get_operation(bundle *b) +{ + return bundle_get_val(b, APP_SVC_K_OPERATION); +} + +SLPAPI const char *appsvc_get_uri(bundle *b) +{ + return bundle_get_val(b, APP_SVC_K_URI); +} + +SLPAPI const char *appsvc_get_mime(bundle *b) +{ + return bundle_get_val(b, APP_SVC_K_MIME); +} + +SLPAPI const char *appsvc_get_data(bundle *b, const char *key) +{ + return bundle_get_val(b, key); +} + +SLPAPI const char **appsvc_get_data_array(bundle *b, const char *key, int *len) +{ + return bundle_get_str_array(b, key, len); +} + +SLPAPI const char *appsvc_get_pkgname(bundle *b) +{ + return bundle_get_val(b, APP_SVC_K_PKG_NAME); +} + +SLPAPI int appsvc_create_result_bundle(bundle *inb, bundle **outb) +{ + int ret = -1; + + if(inb == NULL || outb == NULL) { + _E("bundle is NULL"); + return APPSVC_RET_EINVAL; + } + + ret = aul_create_result_bundle(inb, outb); + + /* add additional bundle */ + /* bundle_add(outb, " ", " "); */ + + if(ret == AUL_R_OK) + ret = APPSVC_RET_OK; + else if(ret == AUL_R_EINVAL) + ret = APPSVC_RET_EINVAL; + else + ret = APPSVC_RET_ERROR; + + return ret; +} + +SLPAPI int appsvc_send_result(bundle *b, appsvc_result_val result) +{ + int ret; + char tmp[MAX_LOCAL_BUFSZ]; + + if(b == NULL){ + _E("appsvc_send_result is NULL"); + return APPSVC_RET_EINVAL; + } + + if(result != APPSVC_RES_OK && result != APPSVC_RES_NOT_OK){ + _E("invalid result %d", (int)result); + return APPSVC_RET_EINVAL; + } + + /* add result_code to bundle */ + snprintf(tmp,MAX_LOCAL_BUFSZ,"%d", (int)result); + ret = __set_bundle(b, APP_SVC_K_RES_VAL, tmp); + if(ret < 0) + return APPSVC_RET_ERROR; + + ret = aul_send_service_result(b); + + /* remove result_code from bundle */ + bundle_del(b, APP_SVC_K_RES_VAL); + + return ret; +} + +SLPAPI int appsvc_set_defapp(const char *op,const char *mime_type,const char *scheme,const char *defapp) +{ + int ret; + + if(op == NULL || defapp == NULL) + return APPSVC_RET_EINVAL; + + ret = _svc_db_add_app(op,mime_type,scheme,defapp); + + if(ret < 0) + return APPSVC_RET_ERROR; + + return APPSVC_RET_OK; +} + +SLPAPI int appsvc_unset_defapp(const char *defapp) +{ + int ret; + + if(defapp == NULL) + return APPSVC_RET_EINVAL; + + ret = _svc_db_delete_with_pkgname(defapp); + + if(ret < 0) + return APPSVC_RET_ERROR; + + return APPSVC_RET_OK; +} + +SLPAPI int appsvc_is_defapp(const char *pkg_name) +{ + return _svc_db_is_defapp(pkg_name); +} + +SLPAPI int appsvc_data_is_array(bundle *b, const char *key) +{ + int type; + type = bundle_get_type(b, key); + + if(type <= 0) + return 0; + + if(type & BUNDLE_TYPE_ARRAY) + return 1; + return 0; +} + + diff --git a/src/appsvc_db.c b/src/appsvc_db.c new file mode 100755 index 0000000..d56ca16 --- /dev/null +++ b/src/appsvc_db.c @@ -0,0 +1,239 @@ +/* + * app-svc + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * 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. + * + */ + + +#include +#include +#include + +#include "appsvc_db.h" +#include "internal.h" + + +#define SVC_DB_PATH "/opt/dbspace/.appsvc.db" +#define QUERY_MAXLEN 4096 +#define BUF_MAX_LEN 1024 + +static sqlite3 *svc_db = NULL; + + +/** + * db initialize + */ +static int __init(void) +{ + int rc; + + if (svc_db) { + _D("Already initialized\n"); + return 0; + } + + rc = sqlite3_open(SVC_DB_PATH, &svc_db); + if(rc) { + _E("Can't open database: %s", sqlite3_errmsg(svc_db)); + goto err; + } + + // Enable persist journal mode + rc = sqlite3_exec(svc_db, "PRAGMA journal_mode = PERSIST", NULL, NULL, NULL); + if(SQLITE_OK!=rc){ + _D("Fail to change journal mode\n"); + goto err; + } + + return 0; +err: + sqlite3_close(svc_db); + return -1; +} + +static int __fini(void) +{ + if (svc_db) { + sqlite3_close(svc_db); + svc_db = NULL; + } + return 0; +} + + +int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, const char *pkg_name) +{ + int ret = -1; + char m[BUF_MAX_LEN]; + char u[BUF_MAX_LEN]; + char query[BUF_MAX_LEN]; + char* error_message = NULL; + + if(__init()<0) + return -1; + + if(op == NULL ) + return -1; + + if(mime_type==NULL) + strncpy(m,"NULL",BUF_MAX_LEN-1); + else + strncpy(m,mime_type,BUF_MAX_LEN-1); + + if(uri==NULL) + strncpy(u,"NULL",BUF_MAX_LEN-1); + else + strncpy(u,uri,BUF_MAX_LEN-1); + + sprintf(query,"insert into appsvc( operation, mime_type, uri, pkg_name) \ + values('%s','%s','%s','%s')",op,m,u,pkg_name); + + if (SQLITE_OK != sqlite3_exec(svc_db, query, NULL, NULL, &error_message)) + { + _E("Don't execute query = %s, error message = %s\n", query, error_message); + return -1; + } + + __fini(); + return 0; +} + +int _svc_db_delete_with_pkgname(const char *pkg_name) +{ + char query[BUF_MAX_LEN]; + char* error_message = NULL; + + if(pkg_name == NULL) { + _E("Invalid argument: data to delete is NULL\n"); + return -1; + } + + if(__init()<0) + return -1; + + snprintf(query, BUF_MAX_LEN, "delete from appsvc where pkg_name = '%s';", pkg_name); + + if (SQLITE_OK != sqlite3_exec(svc_db, query, NULL, NULL, &error_message)) + { + _E("Don't execute query = %s, error message = %s\n", query, error_message); + return -1; + } + + __fini(); + + return 0; +} + +int _svc_db_is_defapp(const char *pkg_name) +{ + char query[BUF_MAX_LEN]; + char* error_message = NULL; + sqlite3_stmt *stmt; + int cnt = 0; + int ret = -1; + + if(pkg_name == NULL) { + _E("Invalid argument: data to delete is NULL\n"); + return 0; + } + + if(__init()<0) + return 0; + + snprintf(query, BUF_MAX_LEN, + "select count(*) from appsvc where pkg_name = '%s';", pkg_name); + + ret = sqlite3_prepare(svc_db, query, sizeof(query), &stmt, NULL); + if (ret != SQLITE_OK) { + return -1; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + cnt = sqlite3_column_int(stmt, 0); + } + sqlite3_finalize(stmt); + + __fini(); + + if(cnt < 1) return 0; + + return 1; +} + +char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri) +{ + char* res = NULL; + char m[BUF_MAX_LEN]; + char u[BUF_MAX_LEN]; + char query[BUF_MAX_LEN]; + char* error_message = NULL; + sqlite3_stmt* stmt; + int ret; + char* pkgname; + + if(op == NULL ) + return NULL; + + if(mime_type==NULL) + strncpy(m,"NULL",BUF_MAX_LEN-1); + else + strncpy(m,mime_type,BUF_MAX_LEN-1); + + if(uri==NULL) + strncpy(u,"NULL",BUF_MAX_LEN-1); + else + strncpy(u,uri,BUF_MAX_LEN-1); + +// if(doubt_sql_injection(mime_type)) +// return NULL; + + if(__init() < 0) + return NULL; + + + sprintf(query,"select pkg_name from appsvc where operation='%s' and mime_type='%s' and uri='%s'",\ + op,m,u); + + _D("query : %s\n",query); + + ret = sqlite3_prepare(svc_db, query, strlen(query), &stmt, NULL); + + if ( ret != SQLITE_OK) { + _E("prepare error\n"); + return NULL; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_DONE) { + return NULL; + } + + pkgname = malloc(BUF_MAX_LEN); + strncpy(pkgname, sqlite3_column_text(stmt, 0),BUF_MAX_LEN-1); + //pkgname = (char*) sqlite3_column_text(stmt, 0); + + _D("pkgname : %s\n",pkgname); + + ret = sqlite3_finalize(stmt); + + __fini(); + + return pkgname; +} + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100755 index 0000000..bf61b55 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,30 @@ +# Test executables +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_CFLAGS}") + +add_executable(appsvc_test + appsvc_test.c) +target_link_libraries(appsvc_test appsvc ${pkgs_LDFLAGS}) +INSTALL(TARGETS appsvc_test DESTINATION bin) + + +### Unit tests ### +## avatar test ## +#add_library(test_avatar STATIC EXCLUDE_FROM_ALL +# test_avatar.c) +#target_link_libraries(test_avatar avatar_v2_lib) + +## Main test function ## +#add_executable(test_all EXCLUDE_FROM_ALL test.c) +#target_link_libraries(test_all test_avatar) +#set_target_properties(test_all +# PROPERTIES SKIP_BUILD_RPATH true +# ) # remove rpath option that is automatically generated by cmake. + +## 'test' target in Makefile ## +# Run test by 'make test' +#add_custom_target(test +# COMMAND ./test_all +# DEPENDS test_all +# WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +# COMMENT "" +# ) diff --git a/test/a.out b/test/a.out new file mode 100755 index 0000000000000000000000000000000000000000..58349cec3f631b8049f24063b81449b2f5121ef4 GIT binary patch literal 8390 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 D9z&XM literal 0 HcmV?d00001 diff --git a/test/appsvc_test.c b/test/appsvc_test.c new file mode 100755 index 0000000..5e80f73 --- /dev/null +++ b/test/appsvc_test.c @@ -0,0 +1,324 @@ +/* +Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +PROPRIETARY/CONFIDENTIAL +This software is the confidential and proprietary information of +SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge that +this software is owned by Samsung and you +shall not disclose such Confidential Information and shall +use it only in accordance with the terms of the license agreement +you entered into with SAMSUNG ELECTRONICS. SAMSUNG make no +representations or warranties about the suitability +of the software, either express or implied, including but not +limited to the implied warranties of merchantability, fitness for +a particular purpose, or non-infringement. +SAMSUNG shall not be liable for any damages suffered by licensee arising out of or +related to this software. +*/ + +#include +#include +#include +#include +#include +#include + +#include "appsvc.h" + + +static char** gargv; +static int gargc; +static char* cmd; +static int apn_pid; + + +typedef struct _test_func_t{ + char* name; + int(*func)(); + char* desc; + char* usage; +}test_func_t; + +__set_bundle_from_args(bundle * kb) +{ + int opt; + char *op = NULL; + char *mime = NULL; + char *uri = NULL; + char *package = NULL; + char* key = NULL; + char* val = NULL; + char* val_array[128]; + + while( (opt = getopt(gargc,gargv,"d:o:m:u:p:")) != -1){ + switch(opt) { + case 'o': + if(optarg) + op = strdup(optarg); + break; + case 'm': + if(optarg) + mime = strdup(optarg); + break; + case 'u': + if(optarg) + uri = strdup(optarg); + break; + case 'p': + if(optarg) + package = strdup(optarg); + break; + case 'd': + if(optarg){ + int i = 0; + key = strtok(optarg,","); + while(val_array[i] = strtok(NULL,",")) + { + i++; + } + if(i==1) + appsvc_add_data(kb, key, val_array[0]); + else if(i>1) + appsvc_add_data_array(kb, key, val_array, i); + } + break; + } + } + + if(op) { + appsvc_set_operation(kb,op); + free(op); + } + if(mime) { + appsvc_set_mime(kb,mime); + free(mime); + } + if(uri) { + appsvc_set_uri(kb,uri); + free(uri); + } + if(package) { + appsvc_set_pkgname(kb,package); + free(package); + } +} + +int run_svc() +{ + static int num=0; + int ret; + bundle *kb=NULL; + kb = bundle_create(); + if(kb == NULL) + { + printf("bundle creation fail\n"); + return -1; + } + printf("[run_svc test]\n"); + + __set_bundle_from_args(kb); + + ret = appsvc_run_service(kb,0,NULL, NULL); + + if(ret >= 0){ + printf("open service success\n"); + if(kb) + { + bundle_free(kb); + kb=NULL; + } + return 0; + } + else{ + printf("open service fail\n"); + if(kb) + { + bundle_free(kb); + kb=NULL; + } + return -1; + } +} + +static void prt_recvd_bundle(const char *key, const int type, const bundle_keyval_t *kv, void *user_data) +{ + char **array_val; + int array_len; + size_t *array_item_size; + + char *val; + size_t *size; + int i; + + if(bundle_keyval_type_is_array(kv) > 0) { + bundle_keyval_get_array_val(kv, &array_val, &array_len, &array_item_size); + + for (i=0;i= 0){ + printf("open service success\n"); + if(kb) + { + bundle_free(kb); + kb=NULL; + } + return 0; + } + else{ + printf("open service fail\n"); + if(kb) + { + bundle_free(kb); + kb=NULL; + } + return -1; + } +} + + +static test_func_t test_func[] = { + + + {"run_svc", run_svc, "run_svc test", + "[usage] run_svc -o [-m ] [-u ] [-d \",\"]..."}, + {"run_svc_res", run_svc_res, "run_svc_res test", + "[usage] run_svc_res -o [-m ] [-u ] [-d \",\"]..."}, + +}; + +int callfunc(char* testname) +{ + test_func_t *tmp; + int res; + int i; + + for(i=0; iname)==0){ + res = tmp->func(); + if(strcmp(testname,"all")){ + if(res < 0) + printf("... test failed\n"); + else + printf("... test successs ret = %d\n", res); + } + } + } + return 0; +} + + +void print_usage(char* progname) +{ + test_func_t *tmp; + int i; + + printf("[usage] %s ...\n",progname); + printf(" - available cmd list\n"); + + for(i=0; iname, tmp->desc); + printf("\t\t%s\n",tmp->usage); + } + +} + + +static Eina_Bool run_func(void *data) +{ + callfunc(cmd); + + if(strcmp(cmd,"run_svc_res") == 0 ) + return 0; + else + ecore_main_loop_quit(); + + return 0; +} + + +int main(int argc, char** argv) +{ + if(argc < 3){ + print_usage(argv[0]); + exit(0); + } + + ecore_init(); + + cmd = argv[1]; + gargc = argc; + gargv = argv; + apn_pid = atoi(argv[2]); + + aul_launch_init(NULL,NULL); + + //aul_listen_app_dead_signal(dead_tracker,NULL); + //aul_listen_app_dead_signal(NULL,NULL); + + ecore_idler_add(run_func, NULL); + + ecore_main_loop_begin(); + + return 0; +} + + -- 2.7.4