4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
37 #include <tzplatform_config.h>
38 #include <pkgmgr-info.h>
40 #include "package-manager.h"
41 #include "pkgmgr_client_debug.h"
42 #include "pkgmgr_client_internal.h"
44 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
46 #define IS_WHITESPACE(CHAR) \
47 ((CHAR == ' ' || CHAR == '\t' || CHAR == '\r' || CHAR == '\n') ? \
50 void _app_str_trim(char *input)
52 char *trim_str = input;
58 if (!IS_WHITESPACE(*input)) {
69 static pkg_plugin_set *plugin_set_list[24] = { 0, };
71 pkg_plugin_set *_pkg_plugin_load_library(const char *pkg_type,
72 const char *library_path)
76 bool (*on_load)(pkg_plugin_set *plugin);
78 if (library_path == NULL || pkg_type == NULL) {
79 ERR("invalid parameter");
83 for (i = 0; plugin_set_list[i]; i++) {
84 if (strcmp(plugin_set_list[i]->pkg_type, pkg_type) == 0) {
85 DBG("already loaded [%s]", library_path);
86 return plugin_set_list[i];
90 if ((library_handle = dlopen(library_path, RTLD_LAZY)) == NULL) {
91 ERR("dlopen is failed library_path[%s]", library_path);
95 if ((on_load = dlsym(library_handle, "pkg_plugin_on_load")) == NULL ||
97 ERR("can not find symbol");
98 dlclose(library_handle);
102 plugin_set_list[i] = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set));
103 if (plugin_set_list[i] == NULL) {
104 ERR("malloc of the plugin_set_list element is failed");
105 dlclose(library_handle);
109 if (on_load(plugin_set_list[i]) != 0) {
110 ERR("pkg_plugin_on_load failed");
111 free(plugin_set_list[i]);
112 dlclose(library_handle);
113 plugin_set_list[i] = NULL;
117 plugin_set_list[i]->plugin_handle = library_handle;
118 snprintf(plugin_set_list[i]->pkg_type,
119 sizeof(plugin_set_list[i]->pkg_type), "%s", pkg_type);
121 DBG("library [%s] is loaded", library_path);
123 return plugin_set_list[i];
126 int _pkg_plugin_get_library_path(const char *pkg_type, char *library_path)
129 char buffer[1024] = { 0 };
131 if (pkg_type == NULL || library_path == NULL) {
132 ERR("invalid argument\n");
136 fp = fopen(PKG_CONF_PATH, "r");
138 ERR("no matching backendlib\n");
139 return PKGMGR_R_ERROR;
143 while (fgets(buffer, 1024, fp) != NULL) {
144 if (buffer[0] == '#')
147 _app_str_trim(buffer);
149 if ((path = strstr(buffer, PKG_BACKENDLIB)) != NULL) {
150 DBG("[%s]\n", buffer);
152 path = path + strlen(PKG_BACKENDLIB);
158 memset(buffer, 0x00, 1024);
165 ERR("no matching backendlib\n");
166 return PKGMGR_R_ERROR;
169 snprintf(library_path, 1024, "%slib%s.so", path, pkg_type);
175 pkg_plugin_set *_package_manager_load_library(const char *pkg_type)
177 char package_path[1024] = { 0, };
178 pkg_plugin_set *plugin_set;
180 if (pkg_type == NULL) {
181 ERR("cannot load library - pkg_type is null");
185 if (_pkg_plugin_get_library_path(pkg_type, package_path) !=
187 ERR("cannot find path");
191 plugin_set = _pkg_plugin_load_library(pkg_type, package_path);
192 if (plugin_set == NULL) {
193 ERR("cannot load library");