merge with master
[platform/core/base/rpm-installer.git] / backend / src / vconf / rpm-vconf-intf.c
1 /*
2  * rpm-installer
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  */
22
23 #include <pkgmgr_installer.h>
24 #include <vconf.h>
25 #include <errno.h>
26
27 #include "rpm-installer-util.h"
28 #include "rpm-installer.h"
29
30 #define VCONF_LOCATION                  "db"
31 #define VCONF_RPM_INSTALLER             VCONF_LOCATION"/private/rpm-installer"
32
33 #define VCONF_RPM_INSTALLER_BACKEND_STATE \
34         VCONF_RPM_INSTALLER"/state"
35 #define VCONF_RPM_INSTALLER_BACKEND_STATEINFO \
36         VCONF_RPM_INSTALLER"/stateinfo"
37
38 #define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND \
39         VCONF_RPM_INSTALLER"/requestinfo/command"
40 #define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME \
41         VCONF_RPM_INSTALLER"/requestinfo/pkgname"
42 #define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS \
43         VCONF_RPM_INSTALLER"/requestinfo/options"
44
45 #define ERR_RETURN_LEN 32
46
47 extern pkgmgr_installer *pi;
48 extern char *gpkgname;
49
50 int _ri_get_backend_state()
51 {
52         int ret = -1;
53         int state = -1;
54
55         _d_msg(DEBUG_INFO,"_ri_get_backend_state\n");
56         ret = vconf_get_int(VCONF_RPM_INSTALLER_BACKEND_STATE, &state);
57         if (ret == -1) {
58                 _d_msg(DEBUG_ERR,
59                        "_ri_get_backend_state: vconf_get_int FAIL\n");
60         } else {
61                 ret = state;
62         }
63         return ret;
64 }
65
66 int _ri_set_backend_state(int state)
67 {
68         int ret = -1;
69
70         if (state == 0) {
71                 vconf_unset_recursive(VCONF_RPM_INSTALLER);
72         }
73
74         _d_msg(DEBUG_INFO,"_ri_set_backend_state\n");
75         ret = vconf_set_int(VCONF_RPM_INSTALLER_BACKEND_STATE, state);
76         if (ret == -1) {
77                 _d_msg(DEBUG_ERR,
78                        "_ri_set_backend_state: vconf_set_int FAIL\n");
79         }
80
81         return ret;
82 }
83
84 int _ri_get_backend_state_info()
85 {
86         int ret = -1;
87         int state = -1;
88         ret = vconf_get_int(VCONF_RPM_INSTALLER_BACKEND_STATEINFO, &state);
89         if (ret == -1) {
90                 _d_msg(DEBUG_ERR,
91                        "_ri_get_backend_state_info: vconf_get_int FAIL\n");
92         } else {
93                 ret = state;
94         /*      _d_msg(DEBUG_INFO,"_ri_get_backend_state_info state[%d]\n", state);*/
95         }
96         return ret;
97 }
98
99 int _ri_set_backend_state_info(int state)
100 {
101         int ret = -1;
102         _d_msg(DEBUG_INFO,"_ri_set_backend_state_info %d\n", state);
103         ret = vconf_set_int(VCONF_RPM_INSTALLER_BACKEND_STATEINFO, state);
104         if (ret == -1)
105                 _d_msg(DEBUG_ERR,
106                        "_ri_set_backend_state_info: vconf_set_int FAIL\n");
107
108         return ret;
109 }
110
111 int _ri_get_last_input_info(char **pkgid, int *preqcommand, int *poptions)
112 {
113         int ret = -1;
114         if (!pkgid || !preqcommand || !poptions)
115                 return -1;
116         ret = vconf_get_int(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND,
117                             preqcommand);
118         if (ret == -1)
119                 _d_msg(DEBUG_ERR,
120                        "_ri_get_last_input_info: VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND: vconf_get_int FAIL\n");
121
122         ret = vconf_get_int(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS,
123                             poptions);
124         if (ret == -1)
125                 _d_msg(DEBUG_ERR,
126                        "_ri_get_last_input_info: VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS: vconf_get_int FAIL\n");
127
128         *pkgid = vconf_get_str(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME);
129         return 0;
130 }
131
132 void _ri_save_last_input_info(char *pkgid, int reqcommand, int options)
133 {
134         keylist_t *kl = NULL;
135         kl = vconf_keylist_new();
136         int ret = -1;
137
138         ret = vconf_keylist_add_int(kl,
139                             VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND,
140                             reqcommand);
141         if (ret == -1)
142                 _d_msg(DEBUG_ERR, "vconf_keylist_add_int FAIL\n");
143         ret = vconf_keylist_add_str(kl,
144                             VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME,
145                             pkgid);
146         if (ret == -1)
147                 _d_msg(DEBUG_ERR, "vconf_keylist_add_str FAIL\n");
148         ret = vconf_keylist_add_int(kl,
149                             VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS,
150                             options);
151         if (ret == -1)
152                 _d_msg(DEBUG_ERR, "vconf_keylist_add_int FAIL\n");
153
154         if (vconf_set(kl))
155                 _d_msg(DEBUG_ERR,
156                        "_ri_save_last_input_info: Failure in writing vconf\n");
157
158         ret = vconf_keylist_free(kl);
159         if (ret == -1)
160                 _d_msg(DEBUG_ERR, "vconf_keylist_free FAIL\n");
161 }
162
163 void _ri_broadcast_status_notification(char *pkgid, char *key, char *val)
164 {
165         char *pkgid_tmp = NULL;
166         char buf[ERR_RETURN_LEN] = {'\0'};
167         int ret_val = 0;
168
169         if (gpkgname != NULL)
170                 pkgid_tmp = gpkgname;
171         else
172                 pkgid_tmp = pkgid;
173
174         ret_val = _ri_string_to_error_no(val);
175         _d_msg(DEBUG_INFO, "pkgid = %s, key = %s, val = %s, ret_val = %d\n", pkgid_tmp, key, val, ret_val);
176
177         if (ret_val == RPM_INSTALLER_ERR_UNKNOWN){
178                 if (pi != NULL)
179                         pkgmgr_installer_send_signal(pi, PKGTYPE, pkgid_tmp, key, val);
180                 else
181                         _d_msg(DEBUG_ERR, "Failure in sending broadcast message\n");
182         }
183         else{
184                 snprintf(buf, ERR_RETURN_LEN - 1, "%d", ret_val);
185                 pkgmgr_installer_send_signal(pi, PKGTYPE, pkgid_tmp, key, buf);
186         }
187 }