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,
74 if (pkgid == NULL || handle == NULL) {
75 _LOGE("invalid parameter");
76 return PMINFO_R_EINVAL;
79 ret = _pkginfo_get_certinfo(pkgid, handle, uid);
80 if (ret != PMINFO_R_OK) _LOGE("failed to get certinfo of %s ", pkgid);
85 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle,
86 pkgmgrinfo_cert_type cert_type,
87 const char **cert_value) {
88 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
89 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
90 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
91 "Invalid certificate type\n");
92 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
93 "Invalid certificate type\n");
94 pkgmgr_certinfo_x *certinfo = NULL;
95 certinfo = (pkgmgr_certinfo_x *)handle;
96 if ((certinfo->cert_info)[cert_type])
97 *cert_value = (certinfo->cert_info)[cert_type];
103 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle) {
104 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
106 pkgmgr_certinfo_x *certinfo = NULL;
107 certinfo = (pkgmgr_certinfo_x *)handle;
108 if (certinfo->pkgid) {
109 free(certinfo->pkgid);
110 certinfo->pkgid = NULL;
112 for (i = 0; i < MAX_CERT_TYPE; i++) {
113 if ((certinfo->cert_info)[i]) {
114 free((certinfo->cert_info)[i]);
115 (certinfo->cert_info)[i] = NULL;
123 API int pkgmgrinfo_create_certinfo_set_handle(
124 pkgmgrinfo_instcertinfo_h *handle) {
125 retvm_if(handle == NULL, PMINFO_R_EINVAL,
126 "Argument supplied to hold return value is NULL\n");
127 pkgmgr_certinfo_x *certinfo = NULL;
129 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
130 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
131 *handle = (void *)certinfo;
135 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle,
136 pkgmgrinfo_instcert_type cert_type,
138 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
139 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
140 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
141 "Invalid certificate type\n");
142 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
143 "Invalid certificate type\n");
144 pkgmgr_certinfo_x *certinfo = NULL;
145 certinfo = (pkgmgr_certinfo_x *)handle;
146 if (certinfo->cert_info[cert_type]) free(certinfo->cert_info[cert_type]);
147 (certinfo->cert_info)[cert_type] = strdup(cert_value);
151 API int pkgmgrinfo_save_certinfo(const char *pkgid,
152 pkgmgrinfo_instcertinfo_h handle, uid_t uid) {
153 if (pkgid == NULL || handle == NULL) {
154 _LOGE("invalid parameter");
155 return PMINFO_R_EINVAL;
157 pkgmgr_certinfo_x *certinfo = (pkgmgr_certinfo_x *)handle;
158 if (certinfo->pkgid == NULL) {
159 certinfo->pkgid = strdup(pkgid);
160 if (certinfo->pkgid == NULL) {
161 _LOGE("Out of memory");
162 return PMINFO_R_ERROR;
165 return _pkginfo_insert_certinfo(pkgid, certinfo, uid);
168 API int pkgmgrinfo_destroy_certinfo_set_handle(
169 pkgmgrinfo_instcertinfo_h handle) {
170 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
172 pkgmgr_certinfo_x *certinfo = NULL;
173 certinfo = (pkgmgr_certinfo_x *)handle;
174 if (certinfo->pkgid) {
175 free(certinfo->pkgid);
176 certinfo->pkgid = NULL;
178 for (i = 0; i < MAX_CERT_TYPE; i++) {
179 if ((certinfo->cert_info)[i]) {
180 free((certinfo->cert_info)[i]);
181 (certinfo->cert_info)[i] = NULL;
189 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid) {
191 _LOGE("invalid parameter");
192 return PMINFO_R_EINVAL;
195 return _pkginfo_delete_certinfo(pkgid);
198 API int pkgmgrinfo_delete_certinfo(const char *pkgid) {
199 return pkgmgrinfo_delete_usr_certinfo(pkgid, _getuid());