10 #include "manager/pkginfo_manager.h"
11 #include "pkgmgr-info.h"
12 #include "pkgmgrinfo_debug.h"
13 #include "pkgmgrinfo_private.h"
15 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
17 retvm_if(handle == NULL, PMINFO_R_EINVAL,
18 "Argument supplied to hold return value is NULL\n");
19 pkgmgr_certinfo_x *certinfo = NULL;
21 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
23 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
24 *handle = (void *)certinfo;
29 API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id,
30 const char *rhs_package_id, uid_t uid,
31 pkgmgrinfo_cert_compare_result_type_e *compare_result)
33 if (lhs_package_id == NULL || rhs_package_id == NULL ||
34 compare_result == NULL) {
35 _LOGE("invalid parameter");
36 return PMINFO_R_EINVAL;
39 return _certinfo_compare_pkg_certinfo(lhs_package_id,
40 rhs_package_id, compare_result);
43 API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(
44 const char *lhs_package_id, const char *rhs_package_id,
45 pkgmgrinfo_cert_compare_result_type_e *compare_result)
47 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id,
48 rhs_package_id, _getuid(), compare_result);
51 API int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(const char *lhs_app_id,
52 const char *rhs_app_id, uid_t uid,
53 pkgmgrinfo_cert_compare_result_type_e *compare_result)
55 if (lhs_app_id == NULL || rhs_app_id == NULL ||
56 compare_result == NULL) {
57 _LOGE("invalid parameter");
58 return PMINFO_R_EINVAL;
61 return _certinfo_compare_app_certinfo(uid,
62 lhs_app_id, rhs_app_id, compare_result);
65 API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id,
66 const char *rhs_app_id,
67 pkgmgrinfo_cert_compare_result_type_e *compare_result)
69 return pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_app_id,
70 rhs_app_id, _getuid(), compare_result);
73 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid,
74 pkgmgrinfo_certinfo_h handle, uid_t uid)
78 if (pkgid == NULL || handle == NULL) {
79 _LOGE("invalid parameter");
80 return PMINFO_R_EINVAL;
83 ret = _pkginfo_get_certinfo(pkgid, handle, uid);
84 if (ret != PMINFO_R_OK)
85 _LOGE("failed to get certinfo of %s ", pkgid);
90 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle,
91 pkgmgrinfo_cert_type cert_type, const char **cert_value)
93 retvm_if(handle == NULL, PMINFO_R_EINVAL,
94 "Argument supplied is NULL\n");
95 retvm_if(cert_value == NULL, PMINFO_R_EINVAL,
96 "Argument supplied is NULL\n");
97 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
98 "Invalid certificate type\n");
99 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
100 "Invalid certificate type\n");
101 pkgmgr_certinfo_x *certinfo = NULL;
103 certinfo = (pkgmgr_certinfo_x *)handle;
104 if ((certinfo->cert_info)[cert_type])
105 *cert_value = (certinfo->cert_info)[cert_type];
111 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
113 retvm_if(handle == NULL, PMINFO_R_EINVAL,
114 "Argument supplied is NULL\n");
116 pkgmgr_certinfo_x *certinfo = NULL;
118 certinfo = (pkgmgr_certinfo_x *)handle;
119 if (certinfo->pkgid) {
120 free(certinfo->pkgid);
121 certinfo->pkgid = NULL;
123 for (i = 0; i < MAX_CERT_TYPE; i++) {
124 if ((certinfo->cert_info)[i]) {
125 free((certinfo->cert_info)[i]);
126 (certinfo->cert_info)[i] = NULL;
134 API int pkgmgrinfo_create_certinfo_set_handle(
135 pkgmgrinfo_instcertinfo_h *handle)
137 retvm_if(handle == NULL, PMINFO_R_EINVAL,
138 "Argument supplied to hold return value is NULL\n");
139 pkgmgr_certinfo_x *certinfo = NULL;
141 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
142 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
143 *handle = (void *)certinfo;
147 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle,
148 pkgmgrinfo_instcert_type cert_type, char *cert_value)
150 retvm_if(handle == NULL, PMINFO_R_EINVAL,
151 "Argument supplied is NULL\n");
152 retvm_if(cert_value == NULL, PMINFO_R_EINVAL,
153 "Argument supplied is NULL\n");
154 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
155 "Invalid certificate type\n");
156 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT,
157 PMINFO_R_EINVAL, "Invalid certificate type\n");
158 pkgmgr_certinfo_x *certinfo = NULL;
160 certinfo = (pkgmgr_certinfo_x *)handle;
161 if (certinfo->cert_info[cert_type])
162 free(certinfo->cert_info[cert_type]);
163 (certinfo->cert_info)[cert_type] = strdup(cert_value);
167 API int pkgmgrinfo_save_certinfo(const char *pkgid,
168 pkgmgrinfo_instcertinfo_h handle, uid_t uid)
170 if (pkgid == NULL || handle == NULL) {
171 _LOGE("invalid parameter");
172 return PMINFO_R_EINVAL;
174 pkgmgr_certinfo_x *certinfo = (pkgmgr_certinfo_x *)handle;
176 if (certinfo->pkgid == NULL) {
177 certinfo->pkgid = strdup(pkgid);
178 if (certinfo->pkgid == NULL) {
179 _LOGE("Out of memory");
180 return PMINFO_R_ERROR;
183 return _pkginfo_insert_certinfo(pkgid, certinfo, uid);
186 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
188 retvm_if(handle == NULL, PMINFO_R_EINVAL,
189 "Argument supplied is NULL\n");
191 pkgmgr_certinfo_x *certinfo = NULL;
193 certinfo = (pkgmgr_certinfo_x *)handle;
194 if (certinfo->pkgid) {
195 free(certinfo->pkgid);
196 certinfo->pkgid = NULL;
198 for (i = 0; i < MAX_CERT_TYPE; i++) {
199 if ((certinfo->cert_info)[i]) {
200 free((certinfo->cert_info)[i]);
201 (certinfo->cert_info)[i] = NULL;
209 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
212 _LOGE("invalid parameter");
213 return PMINFO_R_EINVAL;
216 return _pkginfo_delete_certinfo(pkgid);
219 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
221 return pkgmgrinfo_delete_usr_certinfo(pkgid, _getuid());