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.
26 //#include <device/power.h>
28 #include "rpm-frontend.h"
29 #include "rpm-installer-util.h"
30 #include "rpm-installer.h"
31 #include <pkgmgr_installer.h>
33 #define CONFIG_PATH "/usr/etc/rpm-installer-config.ini"
34 static void __ri_start_processing(void *user_data);
35 static int __ri_is_signature_verification_enabled();
38 /*flag to check whether signature verification is on/off*/
40 int broadcast_disable = 0;
41 extern char scrolllabel[256];
42 extern ri_frontend_data front_data;
43 pkgmgr_installer *pi = NULL;
46 static int __ri_is_signature_verification_enabled()
48 char buffer[1024] = {'\0'};
53 fi = fopen(CONFIG_PATH, "r");
55 _LOGE("Failed to open config file [%s]\n", CONFIG_PATH);
58 while (fgets(buffer, 1024, fi) != NULL) {
59 /* buffer will be like signature=off\n\0*/
60 if (strncmp(buffer, "signature", strlen("signature")) == 0) {
62 /*remove newline character*/
63 buffer[len - 1] = '\0';
64 p = strchr(buffer, '=');
67 if (strcmp(p, "on") == 0)
81 static void __ri_start_processing(void *user_data)
84 if (user_data == NULL) {
85 _LOGE("arg supplied is NULL \n");
88 ri_frontend_data *data = (ri_frontend_data *) user_data;
89 ret = _ri_cmdline_process(data);
91 _ri_cmdline_destroy(data);
95 int main(int argc, char *argv[])
100 ri_frontend_cmdline_arg *data = NULL;
103 _LOGD("------------------------------------------------");
104 _LOGD(" [START] rpm-installer: version=[%s]", RPM_INSTALLER_VERSION);
105 _LOGD("------------------------------------------------");
108 ret = _ri_parse_hybrid(argc, argv);
109 if (ret == RPM_INSTALLER_SUCCESS) {
110 _LOGD("------------------------------------------------");
111 _LOGD(" [END] rpm-installer: _ri_parse_hybrid() succeed.");
112 _LOGD("------------------------------------------------");
113 fprintf(stdout, "%d", ret);
117 for (i = 0; i < argc; i++)
119 const char* pStr = argv[i];
122 _LOGD("argv[%d] = [%s]", i, pStr);
127 // ret = device_power_request_lock(POWER_LOCK_CPU, 0);
128 // _LOGD("device_power_lock_state(POWER_LOCK_CPU, 0), ret = [%d]", ret);
130 /* Initialize the xml parser */
132 // _LOGD("xml parser initialized");
134 /*get signature verification config*/
135 sig_enable = __ri_is_signature_verification_enabled();
136 _LOGD("signature verification mode is [%s]", sig_enable?"on":"off");
138 data = (ri_frontend_cmdline_arg *) calloc(1,
140 (ri_frontend_cmdline_arg));
142 _LOGE("Not Enough Memory\n");
143 ret = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
148 data->req_cmd = INVALID_CMD;
149 data->move_type = -1;
151 /* We need to use pkgmgr_installer_receive request()
152 to parse the arguments */
154 _ri_parse_cmdline(argc, argv, data)) != RPM_INSTALLER_SUCCESS) {
155 _LOGE("_ri_parse_cmdline failed \n");
161 Check for converted wgt package.
163 if(strstr(data->pkgid,".wgt") != NULL){
164 _LOGD("[%s] is eflwgt package.\n", data->pkgid);
165 if(data->req_cmd == INSTALL_CMD){
166 data->req_cmd = EFLWGT_INSTALL_CMD;
167 ret = _ri_process_wgt_package(&data->pkgid);
168 if(ret != RPM_INSTALLER_SUCCESS){
169 _ri_error_no_to_string(ret, &errstr);
170 _LOGE("ERROR:[%s]",errstr);
174 ret = RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED;
175 _ri_error_no_to_string(ret,&errstr);
176 _LOGE("ERROR:[%s]",errstr);
182 if (strstr(data->keyid, "change-state") != NULL) {
183 _LOGE("change-state for [%s]\n", data->pkgid);
184 if (data->req_cmd == INSTALL_CMD) {
185 data->req_cmd = ENABLE_CMD;
186 } else if (data->req_cmd == DELETE_CMD) {
187 data->req_cmd = DISABLE_CMD;
189 ret = RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED;
190 _ri_error_no_to_string(ret,&errstr);
191 _LOGE("ERROR:[%s]",errstr);
196 /*installation for coretpk*/
197 if ((strstr(argv[0], "coretpk") != NULL)
198 && (data->req_cmd == INSTALL_CMD)) {
199 if (stat(data->pkgid, &st)) {
200 ret = RPM_INSTALLER_ERR_UNKNOWN;
201 _ri_error_no_to_string(ret, &errstr);
202 _LOGE("ERROR:[%s]",errstr);
206 if (S_ISDIR(st.st_mode)) {
207 _LOGD("[%s] is directory for tpk.\n", data->pkgid);
208 data->req_cmd = CORETPK_DIRECTORY_INSTALL_CMD;
210 _LOGD("[%s] is tpk package.\n", data->pkgid);
211 data->req_cmd = CORETPK_INSTALL_CMD;
215 front_data.args = data;
216 front_data.security_cookie = NULL;
217 front_data.error = NULL;
219 __ri_start_processing(&front_data);
222 if ((strstr(data->keyid, ".tpk") != NULL) || (strstr(data->pkgid,".wgt") != NULL)) {
224 _LOGD("sync() start");
232 // device_power_release_lock(POWER_LOCK_CPU);
235 pkgmgr_installer_free(pi);
245 _LOGD("------------------------------------------------");
246 _LOGD(" [END] rpm-installer: result=[%d]", ret);
247 _LOGD("------------------------------------------------");