CONFIGURE_FILE(liblaunchpad-hydra.pc.in liblaunchpad-hydra.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblaunchpad-hydra.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+# parser
+ADD_SUBDIRECTORY(parser)
\ No newline at end of file
BuildRequires: pkgconfig(tanchor)
BuildRequires: pkgconfig(dbus-1)
BuildRequires: pkgconfig(iniparser)
+BuildRequires: pkgconfig(libxml-2.0)
Requires(post): /sbin/ldconfig
Requires(post): /usr/bin/systemctl
%install
rm -rf %{buildroot}
+
%make_install
mkdir -p %{buildroot}%{_unitdir_user}/basic.target.wants
mkdir -p %{buildroot}%{_unitdir_user}/sockets.target.wants
%{_unitdir_user}/basic.target.wants/launchpad-process-pool.service
%{_bindir}/launchpad-process-pool
%{_prefix}/share/aul/launchpad.conf
+%{_sysconfdir}/package-manager/parserlib/liblaunchpad-parser.so
+%{_datadir}/parser-plugins/*
%files devel
%{_includedir}/launchpad/*.h
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(launchpad-parser CXX)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(PKGS REQUIRED
+ dlog
+ libxml-2.0
+)
+
+FOREACH(FLAGS ${PKGS_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${FLAGS}")
+ENDFOREACH(FLAGS)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -std=c++11")
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED
+ launchpad_parser_plugin.cc
+ loader_info.cc
+ launchpad_parser_plugin_pkgmgr_interface.cc
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+SET(PLUGINS_LIST_FILE_NAME launchpad_plugins.txt)
+SET(PLUGINS_LIST_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGINS_LIST_FILE_NAME})
+
+SET(PLUGINS_LIST_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/share/parser-plugins)
+
+ADD_DEFINITIONS("-DPLUGINS_LIST_INSTALL_PATH=\"${PLUGINS_LIST_INSTALL_PATH}\"")
+
+INSTALL(FILES ${PLUGINS_LIST_FILE_PATH} DESTINATION ${PLUGINS_LIST_INSTALL_PATH}/)
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS})
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/parserlib)
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 LAUNCHPAD_PARSER_PLUGIN_COMMON_HH_
+#define LAUNCHPAD_PARSER_PLUGIN_COMMON_HH_
+
+#ifdef EXPORT_API
+#undef EXPORT_API
+#endif
+#define EXPORT_API __attribute__((visibility("default")))
+
+#endif // LAUNCHPAD_PARSER_PLUGIN_COMMON_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 <fstream>
+#include <string>
+
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "launchpad_parser_plugin.hh"
+#include "log_private.hh"
+
+#define LOADERS_DIRECTORY_PATH "/opt/share/loaders/"
+
+using namespace std;
+namespace launchpad_parser_plugin {
+
+string LaunchpadParser::GetFilePath(string id) {
+ return "/opt/share/loaders/" + id + ".loader";
+}
+
+int LaunchpadParser::WriteToFile(string pkgid) {
+ if (access(LOADERS_DIRECTORY_PATH, F_OK) != 0)
+ mkdir(LOADERS_DIRECTORY_PATH, 0644);
+
+ LOGI("write to file (%d)", loader_list_.size());
+ for (auto& i : loader_list_) {
+ std::ofstream out_file;
+ LOGI("write ID (%s)", i->GetId().c_str());
+ out_file.open(GetFilePath(i->GetId()));
+ out_file << "[LOADER]\n";
+ out_file << "NAME " + i->GetId() + "\n";
+ out_file << "EXE /usr/bin/launchpad-loader \n";
+ out_file << "APP_TYPE capp|c++app \n";
+ out_file << "DETECTION_METHOD TIMEOUT|VISIBILITY \n";
+ out_file << "TIMEOUT 5000 \n";
+ out_file << "TTL " + to_string(i->GetTimeToLive()) + "\n";
+ out_file << "OWNER " + pkgid + "\n";
+ out_file << "EXTRA loader_type common-loader \n";
+ if (i->GetPreloadLib().size() > 0) {
+ out_file << "EXTRA_ARRAY preload \n";
+ for (auto& lib : i->GetPreloadLib()) {
+ out_file << "EXTRA_ARRAY_VAL /usr/lib/" + lib + "\n";
+ }
+ }
+ out_file.close();
+ }
+ return 0;
+}
+
+bool LaunchpadParser::IsValidId(string loader_id, string pkgid) {
+ ifstream in_file(GetFilePath(loader_id).c_str());
+ if (!in_file.good())
+ return true;
+ string key, val;
+ in_file >> key;
+ while (in_file >> key >> val) {
+ if (key == "OWNER") {
+ LOGI("key (%s), val (%s)", key.c_str(), val.c_str());
+ if (val == pkgid)
+ return true;
+ }
+ }
+ return false;
+}
+
+int LaunchpadParser::Install(xmlDocPtr doc, string pkgid) {
+ xmlNode* root = xmlDocGetRootElement(doc);
+ for (xmlNode* node = root->children; node; node = node->next) {
+ if (!node->name)
+ continue;
+
+ string name = string((char*)node->name);
+ if (name != "provides-appdefined-loader")
+ continue;
+
+ xmlChar* val = xmlGetProp(node, (const xmlChar *)"id");
+ shared_ptr<LoaderInfo> info = make_shared<LoaderInfo>(string((char*)val));
+ if (!IsValidId(info->GetId(), pkgid))
+ return -1;
+
+ xmlChar* ttl = xmlGetProp(node, (const xmlChar *)"time-to-live");
+ if (ttl)
+ info->SetTimeToLive(stoi(string((char*)ttl)));
+
+ for (xmlNode* iter = node->children; iter; iter = iter->next) {
+ if (!iter->name)
+ continue;
+ string child_name = string((char*)iter->name);
+ if (child_name == "preload-library") {
+ xmlChar* libname = xmlGetProp(iter, (const xmlChar *)"name");
+ if (!libname)
+ continue;
+ info->AddPreloadLib(string((char*)libname));
+ }
+ }
+ loader_list_.push_back(info);
+ }
+ WriteToFile(pkgid);
+
+ return 0;
+}
+
+int LaunchpadParser::Upgrade(xmlDocPtr doc, std::string pkgid) {
+ if (UnInstall(doc, pkgid) != 0)
+ return -1;
+
+ return Install(doc, pkgid);
+}
+
+int LaunchpadParser::UnInstall(xmlDocPtr doc, std::string pkgid) {
+ xmlNode* root = xmlDocGetRootElement(doc);
+ for (xmlNode* node = root->children; node; node = node->next) {
+ if (!node->name)
+ continue;
+
+ string name = string((char*)node->name);
+ if (name != "provides-appdefined-loader")
+ continue;
+
+ xmlChar* val = xmlGetProp(node, (const xmlChar *)"id");
+ if (!val)
+ return -1;
+
+ string id = string((char*)val);
+ if (!IsValidId(id, pkgid))
+ return -1;
+ remove(GetFilePath(id).c_str());
+ }
+ return 0;
+}
+
+} // namspace launchpad_parser_plugin
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 LAUNCHPAD_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_
+#define LAUNCHPAD_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_
+
+#include <string>
+#include <list>
+#include <memory>
+#include <libxml/tree.h>
+
+#include "loader_info.hh"
+
+namespace launchpad_parser_plugin {
+
+class LaunchpadParser {
+ public:
+ std::string GetFilePath(std::string id);
+ int WriteToFile(std::string pkgid);
+ int Install(xmlDocPtr doc, std::string pkgid);
+ int Upgrade(xmlDocPtr doc, std::string pkgid);
+ int UnInstall(xmlDocPtr doc, std::string pkgid);
+ bool IsValidId(std::string loader_id, std::string pkgid);
+
+ private:
+ std::list<std::shared_ptr<LoaderInfo>> loader_list_;
+};
+
+} // namespace launchpad_parser_plugin
+
+#endif // LAUNCHPAD_PARSER_PLUGIN_LAUNCHPAD_PARSER_PLUGIN_HH_
+
--- /dev/null
+/*
+ * 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.
+ */
+
+#include <libxml/tree.h>
+
+#include "launchpad_parser_plugin.hh"
+#include "log_private.hh"
+#include "common.hh"
+
+using namespace launchpad_parser_plugin;
+
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char *package)
+{
+ LaunchpadParser parser;
+ LOGI("install");
+ return parser.Install(doc, package);
+}
+
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char *package)
+{
+ LOGI("uninstall");
+ LaunchpadParser parser;
+ return parser.UnInstall(doc, package);
+}
+
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char *package)
+{
+ LOGI("upgrade");
+ LaunchpadParser parser;
+ return parser.Upgrade(doc, package);
+}
+
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERINSTALL(xmlDocPtr doc,
+ const char *package)
+{
+ LOGW("recover install");
+ LaunchpadParser parser;
+ return parser.UnInstall(doc, package);
+}
+
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL(xmlDocPtr doc,
+ const char *package)
+{
+ LOGW("recover uninstall");
+ LaunchpadParser parser;
+ return parser.UnInstall(doc, package);
+}
+
+extern "C" EXPORT_API int PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE(xmlDocPtr doc,
+ const char *package)
+{
+ LOGW("recover upgrade");
+ LaunchpadParser parser;
+ return parser.Upgrade(doc, package);
+}
--- /dev/null
+type="tag";name="provides-appdefined-loader";path="/etc/package-manager/parserlib/liblaunchpad-parser.so";vitalness="true"
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 "loader_info.hh"
+
+using namespace std;
+namespace launchpad_parser_plugin {
+
+LoaderInfo::LoaderInfo(std::string id) : id_(id), time_to_live_(0) {
+}
+
+string LoaderInfo::GetId() {
+ return id_;
+}
+
+int LoaderInfo::GetTimeToLive() {
+ return time_to_live_;
+}
+
+void LoaderInfo::SetTimeToLive(int time) {
+ time_to_live_ = time;
+}
+
+list<string> LoaderInfo::GetPreloadLib() {
+ return preload_lib_list_;
+}
+
+void LoaderInfo::AddPreloadLib(string lib_name) {
+ preload_lib_list_.push_back(lib_name);
+}
+
+} // namspace launchpad_parser_plugin
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 LAUNCHPAD_PARSER_PLUGIN_LOADER_INFO_HH_
+#define LAUNCHPAD_PARSER_PLUGIN_LOADER_INFO_HH_
+
+#include <string>
+#include <list>
+
+namespace launchpad_parser_plugin {
+
+class LoaderInfo {
+ public:
+ LoaderInfo(std::string id);
+ std::string GetId();
+ int GetTimeToLive();
+ void SetTimeToLive(int time);
+ std::list<std::string> GetPreloadLib();
+ void AddPreloadLib(std::string lib_name);
+
+ private:
+ std::string id_;
+ int time_to_live_;
+ std::list<std::string> preload_lib_list_;
+};
+
+} // namespace launchpad_parser_plugin
+
+#endif // LAUNCHPAD_PARSER_PLUGIN_LOADER_INFO_HH_
+
--- /dev/null
+/*
+ * Copyright (c) 2020 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 LAUNCHPAD_PARSER_PLUGIN_LOG_PRIVATE_HH_
+#define LAUNCHPAD_PARSER_PLUGIN_LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "LAUNCHPAD_PARSER_PLUGIN"
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+
+#ifdef _D
+#undef _D
+#endif
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+
+#ifdef _W
+#undef _W
+#endif
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#ifdef _I
+#undef _I
+#endif
+#define _I(fmt, arg...) LOGI(fmt, ##arg)
+
+#endif /* LAUNCHPAD_PARSER_PLUGIN_LOG_PRIVATE_HH_ */