2 * Emulator Extra Package Installation Utility
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
7 * Jinhyung choi <jinhyung2.choi@samsung.com>
8 * Sangho Park <sangho1206.park@samsung.com>
9 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include <sys/types.h>
35 #include "qemu/osdep.h"
36 #include "qemu-common.h"
37 #include "qemu/queue.h"
39 #include "hw/virtio/maru_virtio_evdi.h"
41 #include "extra_pkgs_install.h"
42 #include "emul_state.h"
45 MULTI_DEBUG_CHANNEL(qemu, pkgs);
47 /* FIXME: getting add-on path */
48 static char *get_addon_path(void)
51 const char *parent = "../../../";
52 const char *separator = "/";
54 const char *parent = "..\\..\\..\\";
55 const char *separator = "\\";
60 const char *profile_name = get_profile_name();
65 char *extra_path = (char *)malloc(MAX_PKG_LIST);
67 LOG_SEVERE("cannot alloc extra_path.\n");
71 ret = sprintf(extra_path, "%s%s%s%s%s%s%s",
72 get_bin_path(), parent, profile_name, separator,
73 IMAGE_DIRECTORY, separator, ADDON_DIRECTORY);
75 LOG_SEVERE("ADDON PATH composition is failed.\n");
78 LOG_INFO("ADDON PATH: %s\n", extra_path);
83 static void add_addon_pkgs_name(char *pkgs, char *name)
85 if (strlen(pkgs) == 0) {
88 sprintf(pkgs, "%s, %s", pkgs, name);
92 static void send_to_emuld(char *addon, char *pkgs)
97 char data[MAX_PKG_LIST + MAX_PATH_PKG_LIST];
99 memset(data, 0, sizeof(data));
100 sprintf(data, "%s, %s", addon, pkgs);
102 data_len = strlen(data) + 1;
103 int sndlen = 14 + data_len;
104 char *sndbuf = (char *) g_malloc0(sndlen);
106 LOG_SEVERE("Failed to alloc emuld message\n");
110 memcpy(sndbuf, CMD_PKG, 7);
111 memcpy(sndbuf + 10, &data_len, 2);
112 memcpy(sndbuf + 13, &action, 1);
113 memcpy(sndbuf + 14, data, data_len);
115 LOG_TRACE("sndbuf data: %s\n", sndbuf + 14);
117 ret = send_to_evdi(route_ij, sndbuf, sndlen);
119 LOG_SEVERE("Failed to send emuld message\n");
124 static char *strcasestr(const char *haystack, const char *needle)
126 size_t length_needle;
127 size_t length_haystack;
130 if (!haystack || !needle) {
134 length_needle = strnlen(needle, MAX_PKG_LIST);
135 length_haystack = strnlen(haystack, MAX_PKG_LIST);
137 for (i = 0; i < length_haystack; i++) {
139 for (j = 0; j < length_needle; j++) {
145 if (toupper(c1) != toupper(c2)) {
149 return (char *) haystack + i;
156 #endif /* CONFIG_WIN32 */
161 char sub_addon_path[512];
162 DIR *main_dir = NULL;
164 struct dirent *dir_entry = NULL;
165 struct dirent *sub_dir_entry = NULL;
166 char addon[MAX_PATH_PKG_LIST];
167 char pkgs[MAX_PKG_LIST];
168 char pkg_list[MAX_PKG_LIST];
170 char *addon_path = get_addon_path();
176 main_dir = opendir(addon_path);
178 LOG_INFO("Add-on Directory is empty. No package install is required.\n");
182 memset(pkg_list, 0, sizeof(pkg_list));
184 while ((dir_entry = readdir(main_dir))) {
185 if ((strncasecmp(dir_entry->d_name, ".", 1) != 0) &&
186 (strncasecmp(dir_entry->d_name, "..", 2) != 0)) {
187 LOG_TRACE("reading addon directory: %s\n", dir_entry->d_name);
189 memset(sub_addon_path, 0, 512);
190 memset(addon, 0, sizeof(addon));
191 memset(pkgs, 0, sizeof(pkgs));
193 strcpy(addon, dir_entry->d_name);
196 sprintf(sub_addon_path, "%s/%s", addon_path, dir_entry->d_name);
198 sprintf(sub_addon_path, "%s\\%s", addon_path, dir_entry->d_name);
200 sub_dir = opendir(sub_addon_path);
202 LOG_SEVERE("Add-on sub Directory open failed.");
205 while ((sub_dir_entry = readdir(sub_dir))) {
206 if ((strncasecmp(sub_dir_entry->d_name, ".", 1) != 0) &&
207 (strncasecmp(sub_dir_entry->d_name, "..", 2) != 0)) {
208 if (strlen(sub_dir_entry->d_name) <= 4) {
212 ext = &sub_dir_entry->d_name[strlen(sub_dir_entry->d_name) - 4];
213 if (strcmp(EXT_RPM, ext)) {
216 char* checkDup = strcasestr(pkg_list, sub_dir_entry->d_name);
217 if (checkDup != NULL) {
218 if (checkDup == pkg_list) {
219 LOG_INFO("duplicated package : %s\n", sub_dir_entry->d_name);
223 if (*checkDup == ' ') {
224 LOG_INFO("duplicated package: %s\n", sub_dir_entry->d_name);
230 add_addon_pkgs_name(pkgs, sub_dir_entry->d_name);
231 add_addon_pkgs_name(pkg_list, sub_dir_entry->d_name);
232 LOG_TRACE("reading addon sub directory: %s\n", sub_dir_entry->d_name);
236 LOG_INFO("pkgs: %s, %s\n", addon, pkgs);
238 if (pkg_count == 0) {
239 LOG_INFO("pkgs addon %s is empty. skip!\n", addon);
242 send_to_emuld(addon, pkgs);
253 LOG_INFO("pkg_list: %s\n", pkg_list);