11 #include "manager/pkginfo_manager.h"
12 #include "pkgmgr-info.h"
13 #include "pkgmgrinfo_debug.h"
14 #include "pkgmgrinfo_internal.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
20 retvm_if(handle == NULL, PMINFO_R_EINVAL,
21 "Argument supplied to hold return value is NULL\n");
22 pkgmgr_certinfo_x *certinfo = NULL;
24 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
26 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
27 *handle = (void *)certinfo;
32 API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id,
33 const char *rhs_package_id, uid_t uid,
34 pkgmgrinfo_cert_compare_result_type_e *compare_result)
36 if (lhs_package_id == NULL || rhs_package_id == NULL ||
37 compare_result == NULL) {
38 _LOGE("invalid parameter");
39 return PMINFO_R_EINVAL;
42 return _certinfo_compare_pkg_certinfo(lhs_package_id,
43 rhs_package_id, compare_result);
46 API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(
47 const char *lhs_package_id, const char *rhs_package_id,
48 pkgmgrinfo_cert_compare_result_type_e *compare_result)
50 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id,
51 rhs_package_id, _getuid(), compare_result);
54 API int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(const char *lhs_app_id,
55 const char *rhs_app_id, uid_t uid,
56 pkgmgrinfo_cert_compare_result_type_e *compare_result)
58 if (lhs_app_id == NULL || rhs_app_id == NULL ||
59 compare_result == NULL) {
60 _LOGE("invalid parameter");
61 return PMINFO_R_EINVAL;
64 return _certinfo_compare_app_certinfo(uid,
65 lhs_app_id, rhs_app_id, compare_result);
68 API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id,
69 const char *rhs_app_id,
70 pkgmgrinfo_cert_compare_result_type_e *compare_result)
72 return pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_app_id,
73 rhs_app_id, _getuid(), compare_result);
76 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid,
77 pkgmgrinfo_certinfo_h handle, uid_t uid)
81 if (pkgid == NULL || handle == NULL) {
82 _LOGE("invalid parameter");
83 return PMINFO_R_EINVAL;
86 ret = _pkginfo_get_certinfo(pkgid, handle, uid);
87 if (ret != PMINFO_R_OK)
88 _LOGE("failed to get certinfo of %s ", pkgid);
93 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle,
94 pkgmgrinfo_cert_type cert_type, const char **cert_value)
96 retvm_if(handle == NULL, PMINFO_R_EINVAL,
97 "Argument supplied is NULL\n");
98 retvm_if(cert_value == NULL, PMINFO_R_EINVAL,
99 "Argument supplied is NULL\n");
100 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
101 "Invalid certificate type\n");
102 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
103 "Invalid certificate type\n");
104 pkgmgr_certinfo_x *certinfo = NULL;
106 certinfo = (pkgmgr_certinfo_x *)handle;
107 if ((certinfo->cert_info)[cert_type])
108 *cert_value = (certinfo->cert_info)[cert_type];
114 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
116 retvm_if(handle == NULL, PMINFO_R_EINVAL,
117 "Argument supplied is NULL\n");
119 pkgmgr_certinfo_x *certinfo = NULL;
121 certinfo = (pkgmgr_certinfo_x *)handle;
122 if (certinfo->pkgid) {
123 free(certinfo->pkgid);
124 certinfo->pkgid = NULL;
126 for (i = 0; i < MAX_CERT_TYPE; i++) {
127 if ((certinfo->cert_info)[i]) {
128 free((certinfo->cert_info)[i]);
129 (certinfo->cert_info)[i] = NULL;
137 API int pkgmgrinfo_create_certinfo_set_handle(
138 pkgmgrinfo_instcertinfo_h *handle)
140 retvm_if(handle == NULL, PMINFO_R_EINVAL,
141 "Argument supplied to hold return value is NULL\n");
142 pkgmgr_certinfo_x *certinfo = NULL;
144 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
145 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
146 *handle = (void *)certinfo;
150 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle,
151 pkgmgrinfo_instcert_type cert_type, char *cert_value)
153 retvm_if(handle == NULL, PMINFO_R_EINVAL,
154 "Argument supplied is NULL\n");
155 retvm_if(cert_value == NULL, PMINFO_R_EINVAL,
156 "Argument supplied is NULL\n");
157 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
158 "Invalid certificate type\n");
159 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT,
160 PMINFO_R_EINVAL, "Invalid certificate type\n");
161 pkgmgr_certinfo_x *certinfo = NULL;
163 certinfo = (pkgmgr_certinfo_x *)handle;
164 if (certinfo->cert_info[cert_type])
165 free(certinfo->cert_info[cert_type]);
166 (certinfo->cert_info)[cert_type] = strdup(cert_value);
170 API int pkgmgrinfo_save_certinfo(const char *pkgid,
171 pkgmgrinfo_instcertinfo_h handle, uid_t uid)
173 if (pkgid == NULL || handle == NULL) {
174 _LOGE("invalid parameter");
175 return PMINFO_R_EINVAL;
177 pkgmgr_certinfo_x *certinfo = (pkgmgr_certinfo_x *)handle;
179 if (certinfo->pkgid == NULL) {
180 certinfo->pkgid = strdup(pkgid);
181 if (certinfo->pkgid == NULL) {
182 _LOGE("Out of memory");
183 return PMINFO_R_ERROR;
186 return _pkginfo_insert_certinfo(pkgid, certinfo, uid);
189 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
191 retvm_if(handle == NULL, PMINFO_R_EINVAL,
192 "Argument supplied is NULL\n");
194 pkgmgr_certinfo_x *certinfo = NULL;
196 certinfo = (pkgmgr_certinfo_x *)handle;
197 if (certinfo->pkgid) {
198 free(certinfo->pkgid);
199 certinfo->pkgid = NULL;
201 for (i = 0; i < MAX_CERT_TYPE; i++) {
202 if ((certinfo->cert_info)[i]) {
203 free((certinfo->cert_info)[i]);
204 (certinfo->cert_info)[i] = NULL;
212 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
215 _LOGE("invalid parameter");
216 return PMINFO_R_EINVAL;
219 return _pkginfo_delete_certinfo(pkgid);
222 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
224 return pkgmgrinfo_delete_usr_certinfo(pkgid, _getuid());