35#include "xbps_api_impl.h"
37static xbps_dictionary_t
38get_pkg_in_array(xbps_array_t array,
const char *str,
xbps_trans_type_t tt,
bool virtual)
41 xbps_object_iterator_t iter;
48 iter = xbps_array_iterator(array);
52 while ((obj = xbps_object_iterator_next(iter))) {
53 const char *pkgver = NULL;
54 char pkgname[XBPS_NAME_SIZE] = {0};
56 if (!xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) {
75 if (strcmp(str, pkgver) == 0) {
84 if (strcmp(pkgname, str) == 0) {
90 xbps_object_iterator_release(iter);
93 if (found && tt && (ttype != tt)) {
103xbps_dictionary_t HIDDEN
106 assert(xbps_object_type(a) == XBPS_TYPE_ARRAY);
109 return get_pkg_in_array(a, s, tt,
false);
112xbps_dictionary_t HIDDEN
113xbps_find_virtualpkg_in_array(
struct xbps_handle *xhp,
118 xbps_dictionary_t pkgd;
122 assert(xbps_object_type(a) == XBPS_TYPE_ARRAY);
125 if ((vpkg = vpkg_user_conf(xhp, s))) {
126 if ((pkgd = get_pkg_in_array(a, vpkg, tt,
true)))
130 return get_pkg_in_array(a, s, tt,
true);
133static xbps_dictionary_t
134match_pkg_by_pkgver(xbps_dictionary_t repod,
const char *p)
136 xbps_dictionary_t d = NULL;
137 const char *pkgver = NULL;
138 char pkgname[XBPS_NAME_SIZE] = {0};
147 d = xbps_dictionary_get(repod, pkgname);
149 xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver);
150 if (strcmp(pkgver, p)) {
159static xbps_dictionary_t
160match_pkg_by_pattern(xbps_dictionary_t repod,
const char *p)
162 xbps_dictionary_t d = NULL;
163 const char *pkgver = NULL;
164 char pkgname[XBPS_NAME_SIZE] = {0};
172 return match_pkg_by_pkgver(repod, p);
177 d = xbps_dictionary_get(repod, pkgname);
179 xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver);
191vpkg_user_conf(
struct xbps_handle *xhp,
const char *vpkg)
193 char namebuf[XBPS_NAME_SIZE];
194 xbps_dictionary_t providers;
196 xbps_object_iterator_t iter;
197 const char *pkg = NULL;
200 enum { PKGPATTERN, PKGVER, PKGNAME } match;
216 providers = xbps_dictionary_get(xhp->vpkgd, pkgname);
220 iter = xbps_dictionary_iterator(providers);
223 while ((obj = xbps_object_iterator_next(iter))) {
225 char buf[XBPS_NAME_SIZE] = {0};
226 const char *vpkg_conf = NULL, *vpkgname = NULL;
228 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
229 rpkg = xbps_dictionary_get_keysym(providers, obj);
230 pkg = xbps_string_cstring_nocopy(rpkg);
238 vpkgname = vpkg_conf;
248 xbps_warn_printf(
"invalid: %s\n", vpkg_conf);
252 if (strcmp(buf, vpkgname) != 0) {
257 if (strcmp(vpkg, vpkgname) != 0) {
262 xbps_dbg_printf(
"%s: vpkg_conf %s pkg %s vpkgname %s\n", __func__, vpkg_conf, pkg, vpkgname);
266 xbps_object_iterator_release(iter);
268 return found ? pkg : NULL;
271xbps_dictionary_t HIDDEN
272xbps_find_virtualpkg_in_conf(
struct xbps_handle *xhp,
276 xbps_object_iterator_t iter;
278 xbps_dictionary_t providers;
279 xbps_dictionary_t pkgd = NULL;
282 if (!xhp->vpkgd_conf)
285 providers = xbps_dictionary_get(xhp->vpkgd_conf, pkg);
289 iter = xbps_dictionary_iterator(providers);
292 while ((obj = xbps_object_iterator_next(iter))) {
294 char buf[XBPS_NAME_SIZE] = {0};
295 const char *vpkg_conf = NULL, *vpkgname = NULL;
297 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
298 rpkg = xbps_dictionary_get_keysym(providers, obj);
299 cur = xbps_string_cstring_nocopy(rpkg);
307 vpkgname = vpkg_conf;
330 if (strcmp(buf, vpkgname)) {
334 if (strcmp(pkg, vpkgname)) {
338 xbps_dbg_printf(
"%s: found: %s %s %s\n", __func__, vpkg_conf, cur, vpkgname);
342 pkgd = match_pkg_by_pattern(d, cur);
344 pkgd = match_pkg_by_pkgver(d, cur);
346 pkgd = xbps_dictionary_get(d, cur);
349 xbps_object_iterator_release(iter);
354xbps_dictionary_t HIDDEN
355xbps_find_virtualpkg_in_dict(
struct xbps_handle *xhp,
360 xbps_object_iterator_t iter;
361 xbps_dictionary_t pkgd = NULL;
366 vpkg = vpkg_user_conf(xhp, pkg);
369 pkgd = match_pkg_by_pattern(d, vpkg);
371 pkgd = match_pkg_by_pkgver(d, vpkg);
373 pkgd = xbps_dictionary_get(d, vpkg);
379 iter = xbps_dictionary_iterator(d);
382 while ((obj = xbps_object_iterator_next(iter))) {
383 pkgd = xbps_dictionary_get_keysym(d, obj);
385 xbps_object_iterator_release(iter);
389 xbps_object_iterator_release(iter);
394xbps_dictionary_t HIDDEN
395xbps_find_pkg_in_dict(xbps_dictionary_t d,
const char *pkg)
397 xbps_dictionary_t pkgd = NULL;
400 pkgd = match_pkg_by_pattern(d, pkg);
402 pkgd = match_pkg_by_pkgver(d, pkg);
404 pkgd = xbps_dictionary_get(d, pkg);
Generic XBPS structure handler for initialization.
bool xbps_match_virtual_pkg_in_dict(xbps_dictionary_t pkgd, const char *str)
xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf
const char * xbps_pkgpattern_version(const char *pattern)
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)
int xbps_pkgpattern_match(const char *pkgver, const char *pattern)
const char * xbps_pkg_version(const char *pkg)
bool xbps_pkgpattern_name(char *dst, size_t len, const char *pattern)