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) {
19 retvm_if(handle == NULL, PMINFO_R_EINVAL,
20 "Argument supplied to hold return value is NULL\n");
21 pkgmgr_certinfo_x *certinfo = NULL;
22 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
24 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
25 *handle = (void *)certinfo;
30 API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(
31 const char *lhs_package_id, const char *rhs_package_id, uid_t uid,
32 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, rhs_package_id,
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) {
46 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(
47 lhs_package_id, rhs_package_id, _getuid(), compare_result);
50 API int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(
51 const char *lhs_app_id, const char *rhs_app_id, uid_t uid,
52 pkgmgrinfo_cert_compare_result_type_e *compare_result) {
53 if (lhs_app_id == NULL || rhs_app_id == NULL || compare_result == NULL) {
54 _LOGE("invalid parameter");
55 return PMINFO_R_EINVAL;
58 return _certinfo_compare_app_certinfo(
59 uid, lhs_app_id, rhs_app_id, compare_result);
62 API int pkgmgrinfo_pkginfo_compare_app_cert_info(
63 const char *lhs_app_id, const char *rhs_app_id,
64 pkgmgrinfo_cert_compare_result_type_e *compare_result) {
65 return pkgmgrinfo_pkginfo_compare_usr_app_cert_info(
66 lhs_app_id, rhs_app_id, _getuid(), compare_result);
69 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid,
70 pkgmgrinfo_certinfo_h handle,
73 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)handle;
75 if (pkgid == NULL || handle == NULL) {
76 _LOGE("invalid parameter");
77 return PMINFO_R_EINVAL;
80 ret = _pkginfo_get_certinfo(pkgid, &info, uid);
81 if (ret != PMINFO_R_OK) _LOGE("failed to get certinfo of %s ", pkgid);
86 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle,
87 pkgmgrinfo_cert_type cert_type,
88 const char **cert_value) {
89 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
90 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
91 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
92 "Invalid certificate type\n");
93 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
94 "Invalid certificate type\n");
95 pkgmgr_certinfo_x *certinfo = NULL;
96 certinfo = (pkgmgr_certinfo_x *)handle;
97 if ((certinfo->cert_info)[cert_type])
98 *cert_value = (certinfo->cert_info)[cert_type];
104 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle) {
105 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
107 pkgmgr_certinfo_x *certinfo = NULL;
108 certinfo = (pkgmgr_certinfo_x *)handle;
109 if (certinfo->pkgid) {
110 free(certinfo->pkgid);
111 certinfo->pkgid = NULL;
113 for (i = 0; i < MAX_CERT_TYPE; i++) {
114 if ((certinfo->cert_info)[i]) {
115 free((certinfo->cert_info)[i]);
116 (certinfo->cert_info)[i] = NULL;
124 API int pkgmgrinfo_create_certinfo_set_handle(
125 pkgmgrinfo_instcertinfo_h *handle) {
126 retvm_if(handle == NULL, PMINFO_R_EINVAL,
127 "Argument supplied to hold return value is NULL\n");
128 pkgmgr_certinfo_x *certinfo = NULL;
130 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
131 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
132 *handle = (void *)certinfo;
136 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle,
137 pkgmgrinfo_instcert_type cert_type,
139 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
140 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
141 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
142 "Invalid certificate type\n");
143 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
144 "Invalid certificate type\n");
145 pkgmgr_certinfo_x *certinfo = NULL;
146 certinfo = (pkgmgr_certinfo_x *)handle;
147 if (certinfo->cert_info[cert_type]) free(certinfo->cert_info[cert_type]);
148 (certinfo->cert_info)[cert_type] = strdup(cert_value);
152 API int pkgmgrinfo_save_certinfo(const char *pkgid,
153 pkgmgrinfo_instcertinfo_h handle, uid_t uid) {
154 if (pkgid == NULL || handle == NULL) {
155 _LOGE("invalid parameter");
156 return PMINFO_R_EINVAL;
158 pkgmgr_certinfo_x *certinfo = (pkgmgr_certinfo_x *)handle;
159 if (certinfo->pkgid == NULL) {
160 certinfo->pkgid = strdup(pkgid);
161 if (certinfo->pkgid == NULL) {
162 _LOGE("Out of memory");
163 return PMINFO_R_ERROR;
166 return _pkginfo_insert_certinfo(pkgid, certinfo, uid);
169 API int pkgmgrinfo_destroy_certinfo_set_handle(
170 pkgmgrinfo_instcertinfo_h handle) {
171 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
173 pkgmgr_certinfo_x *certinfo = NULL;
174 certinfo = (pkgmgr_certinfo_x *)handle;
175 if (certinfo->pkgid) {
176 free(certinfo->pkgid);
177 certinfo->pkgid = NULL;
179 for (i = 0; i < MAX_CERT_TYPE; i++) {
180 if ((certinfo->cert_info)[i]) {
181 free((certinfo->cert_info)[i]);
182 (certinfo->cert_info)[i] = NULL;
190 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid) {
192 _LOGE("invalid parameter");
193 return PMINFO_R_EINVAL;
196 return _pkginfo_delete_certinfo(pkgid);
199 API int pkgmgrinfo_delete_certinfo(const char *pkgid) {
200 return pkgmgrinfo_delete_usr_certinfo(pkgid, _getuid());