10 #include "manager/pkginfo_manager.h"
11 #include "pkgmgr-info.h"
12 #include "pkgmgrinfo_debug.h"
13 #include "pkgmgrinfo_private.h"
14 #include "pkgmgr_parser.h"
16 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
18 retvm_if(handle == NULL, PMINFO_R_EINVAL,
19 "Argument supplied to hold return value is NULL\n");
20 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(const char *lhs_package_id,
31 const char *rhs_package_id, uid_t uid,
32 pkgmgrinfo_cert_compare_result_type_e *compare_result)
34 if (lhs_package_id == NULL || rhs_package_id == NULL ||
35 compare_result == NULL) {
36 _LOGE("invalid parameter");
37 return PMINFO_R_EINVAL;
40 return _certinfo_compare_pkg_certinfo(lhs_package_id,
41 rhs_package_id, compare_result);
44 API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(
45 const char *lhs_package_id, const char *rhs_package_id,
46 pkgmgrinfo_cert_compare_result_type_e *compare_result)
48 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id,
49 rhs_package_id, _getuid(), compare_result);
52 API int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(const char *lhs_app_id,
53 const char *rhs_app_id, uid_t uid,
54 pkgmgrinfo_cert_compare_result_type_e *compare_result)
56 if (lhs_app_id == NULL || rhs_app_id == NULL ||
57 compare_result == NULL) {
58 _LOGE("invalid parameter");
59 return PMINFO_R_EINVAL;
62 return _certinfo_compare_app_certinfo(uid,
63 lhs_app_id, rhs_app_id, compare_result);
66 API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id,
67 const char *rhs_app_id,
68 pkgmgrinfo_cert_compare_result_type_e *compare_result)
70 return pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_app_id,
71 rhs_app_id, _getuid(), compare_result);
74 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid,
75 pkgmgrinfo_certinfo_h handle, uid_t uid)
79 if (pkgid == NULL || handle == NULL) {
80 _LOGE("invalid parameter");
81 return PMINFO_R_EINVAL;
84 ret = _pkginfo_get_certinfo(pkgid, handle, uid);
85 if (ret != PMINFO_R_OK)
86 _LOGE("failed to get certinfo of %s ", pkgid);
91 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle,
92 pkgmgrinfo_cert_type cert_type, const char **cert_value)
94 retvm_if(handle == NULL, PMINFO_R_EINVAL,
95 "Argument supplied is NULL\n");
96 retvm_if(cert_value == NULL, PMINFO_R_EINVAL,
97 "Argument supplied is NULL\n");
98 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
99 "Invalid certificate type\n");
100 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
101 "Invalid certificate type\n");
102 pkgmgr_certinfo_x *certinfo = NULL;
104 certinfo = (pkgmgr_certinfo_x *)handle;
105 if ((certinfo->cert_info)[cert_type])
106 *cert_value = (certinfo->cert_info)[cert_type];
112 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
114 retvm_if(handle == NULL, PMINFO_R_EINVAL,
115 "Argument supplied is NULL\n");
117 pkgmgr_certinfo_x *certinfo = NULL;
119 certinfo = (pkgmgr_certinfo_x *)handle;
120 if (certinfo->pkgid) {
121 free(certinfo->pkgid);
122 certinfo->pkgid = NULL;
124 for (i = 0; i < MAX_CERT_TYPE; i++) {
125 if ((certinfo->cert_info)[i]) {
126 free((certinfo->cert_info)[i]);
127 (certinfo->cert_info)[i] = NULL;
135 API int pkgmgrinfo_create_certinfo_set_handle(
136 pkgmgrinfo_instcertinfo_h *handle)
138 retvm_if(handle == NULL, PMINFO_R_EINVAL,
139 "Argument supplied to hold return value is NULL\n");
140 pkgmgr_certinfo_x *certinfo = NULL;
142 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
143 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
144 *handle = (void *)certinfo;
148 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle,
149 pkgmgrinfo_instcert_type cert_type, char *cert_value)
151 retvm_if(handle == NULL, PMINFO_R_EINVAL,
152 "Argument supplied is NULL\n");
153 retvm_if(cert_value == NULL, PMINFO_R_EINVAL,
154 "Argument supplied is NULL\n");
155 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
156 "Invalid certificate type\n");
157 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT,
158 PMINFO_R_EINVAL, "Invalid certificate type\n");
159 pkgmgr_certinfo_x *certinfo = NULL;
161 certinfo = (pkgmgr_certinfo_x *)handle;
162 if (certinfo->cert_info[cert_type])
163 free(certinfo->cert_info[cert_type]);
164 (certinfo->cert_info)[cert_type] = strdup(cert_value);
168 API int pkgmgrinfo_save_certinfo(const char *pkgid,
169 pkgmgrinfo_instcertinfo_h handle, uid_t uid)
171 if (pkgid == NULL || handle == NULL) {
172 _LOGE("invalid parameter");
173 return PMINFO_R_EINVAL;
175 pkgmgr_certinfo_x *certinfo = (pkgmgr_certinfo_x *)handle;
177 if (certinfo->pkgid == NULL) {
178 certinfo->pkgid = strdup(pkgid);
179 if (certinfo->pkgid == NULL) {
180 _LOGE("Out of memory");
181 return PMINFO_R_ERROR;
184 return _pkginfo_insert_certinfo(pkgid, certinfo, uid);
187 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
189 retvm_if(handle == NULL, PMINFO_R_EINVAL,
190 "Argument supplied is NULL\n");
192 pkgmgr_certinfo_x *certinfo = NULL;
194 certinfo = (pkgmgr_certinfo_x *)handle;
195 if (certinfo->pkgid) {
196 free(certinfo->pkgid);
197 certinfo->pkgid = NULL;
199 for (i = 0; i < MAX_CERT_TYPE; i++) {
200 if ((certinfo->cert_info)[i]) {
201 free((certinfo->cert_info)[i]);
202 (certinfo->cert_info)[i] = NULL;
210 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
213 _LOGE("invalid parameter");
214 return PMINFO_R_EINVAL;
217 return _pkginfo_delete_certinfo(pkgid);
220 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
222 return pkgmgrinfo_delete_usr_certinfo(pkgid, _getuid());