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.
31 #include <appcore-efl.h>
34 #include "native_installer_util.h"
35 #include "nativeinstaller.h"
36 #include<pkgmgr_installer.h>
37 #include <security-server.h>
40 extern struct appdata ad;
41 extern pkgmgr_installer *pi;
42 struct frontenddata frontdata;
43 char scrolllabel[256];
46 static void __show_usage(char **arg);
47 static int __process_request(struct frontendcmdlinearg *pardata);
50 extern int main_of_backend(char *keyid, char *pkgname, char *reqcommand);
52 static void __show_usage(char **arg)
57 while (arg[i] != NULL) {
58 snprintf(buffer, 256, "%s %s", tBuff, arg[i]);
59 strncpy(tBuff, buffer, 255);
63 d_msg_frontend(DEBUG_INFO, "%s\n", buffer);
64 d_msg_frontend(DEBUG_INFO,
65 "\nnative-backend usage\n native-backend -k <keyid> <command> <pkg_name | pkg_path> [-q] \n\n");
66 d_msg_frontend(DEBUG_INFO, "<Commands> \n");
67 d_msg_frontend(DEBUG_INFO,
68 "\t -i <PackageFilePath> : install package file \n");
69 d_msg_frontend(DEBUG_INFO,
70 "\t -k <keyid> : key id file \n");
71 d_msg_frontend(DEBUG_INFO,
72 "\t -r : (recover). Must ignore specific package name or path \n");
73 d_msg_frontend(DEBUG_INFO,
74 "\t -d <PackageName> : delete a package with Package Name \n");
75 d_msg_frontend(DEBUG_INFO,
76 "\t -q : (quite) run in background without any user interaction \n");
79 int _parse_cmdline(int argc, char **argv, struct frontendcmdlinearg *pardata)
81 int reqcommand = INVALID_CMD;
82 const char *ppkgname = NULL;
84 const char *pkeyid = NULL;
86 /*const char *licensePath = NULL;
88 char licenseBuf[1024*4] = {'\0'};
89 unsigned int licenseBuflen = 0;
90 char decLicenseBuf[1024*4] = {'\0'};
91 unsigned int decLicenseBuflen = 0;
92 char decPackageName[256] = {'\0'};
93 char temp[256] = {'\0'};
95 pi = pkgmgr_installer_new();
97 d_msg_frontend(DEBUG_ERR,
98 "Failure in creating the pkgmgr_installer object \n");
99 return NATIVEINSTALLER_ERR_WRONG_PARAM;
101 ret = pkgmgr_installer_receive_request(pi, argc, argv);
103 d_msg_frontend(DEBUG_ERR,
104 "pkgmgr_installer_receive_request failed \n");
105 return NATIVEINSTALLER_ERR_WRONG_PARAM;
107 ret = pkgmgr_installer_get_request_type(pi);
109 case PKGMGR_REQ_INSTALL:
110 reqcommand = INSTALL_CMD;
112 case PKGMGR_REQ_UNINSTALL:
113 reqcommand = DELETE_CMD;
115 case PKGMGR_REQ_RECOVER:
116 reqcommand = RECOVER_CMD;
118 case PKGMGR_REQ_CLEAR:
119 reqcommand = CLEAR_CMD;
121 case PKGMGR_REQ_PERM:
123 case PKGMGR_REQ_INVALID:
124 reqcommand = INVALID_CMD;
129 if (reqcommand != RECOVER_CMD) {
130 ppkgname = pkgmgr_installer_get_request_info(pi);
132 d_msg_frontend(DEBUG_ERR,
133 "pkgmgr_installer_get_request_info failed \n");
134 return NATIVEINSTALLER_ERR_WRONG_PARAM;
136 pkeyid = pkgmgr_installer_get_session_id(pi);
138 d_msg_frontend(DEBUG_ERR,
139 "pkgmgr_installer_get_session_id failed \n");
140 return NATIVEINSTALLER_ERR_WRONG_PARAM;
143 quiteopt = pkgmgr_installer_is_quiet(pi);
144 if (quiteopt != 0 && quiteopt != 1) {
145 d_msg_frontend(DEBUG_ERR,
146 "pkgmgr_installer_is_quiet failed \n");
147 return NATIVEINSTALLER_ERR_WRONG_PARAM;
151 if (reqcommand != INSTALL_CMD && reqcommand != DELETE_CMD
152 && reqcommand != RECOVER_CMD && reqcommand != CLEAR_CMD) {
153 d_msg_frontend(DEBUG_ERR, "invalid command \n");
157 pardata->reqcommand = reqcommand;
158 pardata->ppkgname = (char *)ppkgname;
159 pardata->quiteoptions = quiteopt;
160 pardata->pkeyid = (char *)pkeyid;
161 return NATIVEINSTALLER_SUCCESS;
164 d_msg_frontend(DEBUG_ERR, "Error in parsing input parameter\n");
166 return NATIVEINSTALLER_ERR_WRONG_PARAM;
170 static int __process_request(struct frontendcmdlinearg *pardata)
174 return NATIVEINSTALLER_ERR_WRONG_PARAM;
175 char *pkgname = NULL;
177 if (pardata->reqcommand != RECOVER_CMD) {
178 pkgname = strdup(pardata->ppkgname);
179 if (PM_UNLIKELY(pkgname == NULL)) {
180 d_msg_frontend(DEBUG_ERR, "strdup failed\n");
181 return NATIVEINSTALLER_ERR_WRONG_PARAM;
183 keyid = strdup(pardata->pkeyid);
184 if (PM_UNLIKELY(keyid == NULL)) {
185 d_msg_frontend(DEBUG_ERR, "strdup failed\n");
187 return NATIVEINSTALLER_ERR_WRONG_PARAM;
190 switch (pardata->reqcommand) {
192 d_msg_frontend(DEBUG_INFO, "native-backend -i %s\n", pkgname);
193 ret = main_of_backend(keyid, pkgname, "install");
196 d_msg_frontend(DEBUG_INFO, "native-backend -d %s\n", pkgname);
197 ret = main_of_backend(keyid, pkgname, "remove");
200 d_msg_frontend(DEBUG_INFO, "native-backend -r \n");
201 ret = main_of_backend(keyid, pkgname, "recover");
204 d_msg_frontend(DEBUG_INFO, "native-backend -c %s\n", pkgname);
205 ret = main_of_backend(keyid, pkgname, "clear");
208 d_msg_frontend(DEBUG_ERR,
209 "Error Never Come Here as Error is already checked\n");
224 void stat_cb(const char *pkg_name, const char *key, const char *val)
229 if (NULL == pkg_name || NULL == key || NULL == val) {
230 d_msg_frontend(DEBUG_ERR, "Either pkg_name/key/val is NULL\n");
231 return; /*TODO: handle error. */
234 char *pkg_name_modified = NULL;
237 char *pkgname = NULL;
238 char *saveptr = NULL;
240 pkg_name_modified = (char *)malloc(strlen(pkg_name) + 1);
241 if (pkg_name_modified == NULL) {
242 d_msg_frontend(DEBUG_ERR,
243 "pkg_name_modified is NULL. Malloc failed\n");
246 memset(pkg_name_modified, '\0', strlen(pkg_name) + 1);
247 memcpy(pkg_name_modified, pkg_name, strlen(pkg_name));
249 result = strtok_r(pkg_name_modified, delims, &saveptr);
250 while (result != NULL) {
252 result = strtok_r(NULL, delims, &saveptr);
256 char *pkgname = pkg_name;
259 if (strcmp(key, "install_percent") == 0) {
261 } else if (strcmp(key, "error") == 0) {
262 /* Store the error to be display to the user */
263 frontdata.perror_string = strdup(val);
264 } else if (strcmp(key, "end") == 0) {
266 char requesttype[32];
267 switch (frontdata.cmdlineargs->reqcommand) {
269 snprintf(requesttype, sizeof(requesttype), _("Installation"));
272 snprintf(requesttype, sizeof(requesttype), _("Deletion"));
275 snprintf(requesttype, sizeof(requesttype), _("Clear Data"));
278 snprintf(requesttype, sizeof(requesttype), _("Recovery"));
282 if (frontdata.perror_string) {
284 snprintf(scrolllabel, sizeof(scrolllabel), "%s :: %s:: %s:: %s",
285 requesttype, pkgname,
286 dgettext("sys_string", "IDS_COM_POP_ERROR"),
287 frontdata.perror_string);
288 d_msg_frontend(DEBUG_ERR, "%s\n", scrolllabel);
290 _string_to_error_no(frontdata.perror_string);
291 d_msg_frontend(DEBUG_ERR, "%d\n", greturn_main_value);
292 /*gReturnMainValue = -1; */
294 snprintf(scrolllabel, sizeof(scrolllabel), " %s :: %s :: %s",
295 requesttype, pkgname,
296 dgettext("sys_string", "IDS_COM_POP_SUCCESS"));
297 d_msg_frontend(DEBUG_INFO, "%s\n", scrolllabel);
298 greturn_main_value = 0;
306 int _cmdline_process(struct frontenddata *data)
313 struct frontendcmdlinearg *pardata = data->cmdlineargs;
315 cookie_size = security_server_get_cookie_size();
316 /* If security server is down or some other
317 error occured, raise failure */
318 if (0 >= cookie_size) {
319 /* TODO: raise error */
320 d_msg_frontend(DEBUG_ERR,
321 "security_server_get_cookie_size: Security server down \n");
323 cookie = calloc(cookie_size, sizeof(char));
328 security_server_request_cookie(cookie, cookie_size);
329 /* TODO: Check cookie_ret...
330 (See security-server.h to check return code) */
334 d_msg_frontend(DEBUG_INFO, "Frontend Cookies is generated - size[%d]\n", cookie_size);
336 data->gptr_security_cookie = cookie;
338 ret = __process_request(pardata);
339 if (ret != NATIVEINSTALLER_SUCCESS) {
340 d_msg_frontend(DEBUG_ERR, "__process_request: Error\n");
344 return NATIVEINSTALLER_SUCCESS;
348 if (data->gptr_security_cookie) {
349 free(data->gptr_security_cookie);
350 data->gptr_security_cookie = NULL;
356 int _cmdline_destroy(struct frontenddata *data)
361 if (data->gptr_security_cookie)
362 free(data->gptr_security_cookie);