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};
145 xbps_error_printf(
"invalid pkgver: %s\n", p);
150 d = xbps_dictionary_get(repod, pkgname);
155 if (!xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver)) {
156 xbps_error_printf(
"missing `pkgver` property\n");
160 if (strcmp(pkgver, p) != 0) {
168static xbps_dictionary_t
169match_pkg_by_pattern(xbps_dictionary_t repod,
const char *p)
171 xbps_dictionary_t d = NULL;
172 const char *pkgver = NULL;
173 char pkgname[XBPS_NAME_SIZE] = {0};
181 return match_pkg_by_pkgver(repod, p);
183 xbps_error_printf(
"invalid pkgpattern: %s\n", p);
188 d = xbps_dictionary_get(repod, pkgname);
193 if (!xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver)) {
194 xbps_error_printf(
"missing `pkgver` property`\n");
207vpkg_user_conf(
struct xbps_handle *xhp,
const char *vpkg)
209 char namebuf[XBPS_NAME_SIZE];
210 xbps_dictionary_t providers;
212 xbps_object_iterator_t iter;
213 const char *pkg = NULL;
216 enum { PKGPATTERN, PKGVER, PKGNAME } match;
232 providers = xbps_dictionary_get(xhp->vpkgd, pkgname);
236 iter = xbps_dictionary_iterator(providers);
239 while ((obj = xbps_object_iterator_next(iter))) {
241 char buf[XBPS_NAME_SIZE] = {0};
242 const char *vpkg_conf = NULL, *vpkgname = NULL;
244 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
245 rpkg = xbps_dictionary_get_keysym(providers, obj);
246 pkg = xbps_string_cstring_nocopy(rpkg);
254 vpkgname = vpkg_conf;
264 xbps_warn_printf(
"invalid: %s\n", vpkg_conf);
268 if (strcmp(buf, vpkgname) != 0) {
273 if (strcmp(vpkg, vpkgname) != 0) {
278 xbps_dbg_printf(
"%s: vpkg_conf %s pkg %s vpkgname %s\n", __func__, vpkg_conf, pkg, vpkgname);
282 xbps_object_iterator_release(iter);
284 return found ? pkg : NULL;
287xbps_dictionary_t HIDDEN
288xbps_find_virtualpkg_in_conf(
struct xbps_handle *xhp,
292 xbps_object_iterator_t iter;
294 xbps_dictionary_t providers;
295 xbps_dictionary_t pkgd = NULL;
298 if (!xhp->vpkgd_conf)
301 providers = xbps_dictionary_get(xhp->vpkgd_conf, pkg);
305 iter = xbps_dictionary_iterator(providers);
308 while ((obj = xbps_object_iterator_next(iter))) {
310 char buf[XBPS_NAME_SIZE] = {0};
311 const char *vpkg_conf = NULL, *vpkgname = NULL;
313 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
314 rpkg = xbps_dictionary_get_keysym(providers, obj);
315 cur = xbps_string_cstring_nocopy(rpkg);
323 vpkgname = vpkg_conf;
346 if (strcmp(buf, vpkgname)) {
350 if (strcmp(pkg, vpkgname)) {
354 xbps_dbg_printf(
"%s: found: %s %s %s\n", __func__, vpkg_conf, cur, vpkgname);
358 pkgd = match_pkg_by_pattern(d, cur);
360 pkgd = match_pkg_by_pkgver(d, cur);
362 pkgd = xbps_dictionary_get(d, cur);
365 xbps_object_iterator_release(iter);
370xbps_dictionary_t HIDDEN
371xbps_find_virtualpkg_in_dict(
struct xbps_handle *xhp,
376 xbps_object_iterator_t iter;
377 xbps_dictionary_t pkgd = NULL;
382 vpkg = vpkg_user_conf(xhp, pkg);
385 pkgd = match_pkg_by_pattern(d, vpkg);
387 pkgd = match_pkg_by_pkgver(d, vpkg);
389 pkgd = xbps_dictionary_get(d, vpkg);
395 iter = xbps_dictionary_iterator(d);
398 while ((obj = xbps_object_iterator_next(iter))) {
399 pkgd = xbps_dictionary_get_keysym(d, obj);
401 xbps_object_iterator_release(iter);
405 xbps_object_iterator_release(iter);
410xbps_dictionary_t HIDDEN
411xbps_find_pkg_in_dict(xbps_dictionary_t d,
const char *pkg)
413 xbps_dictionary_t pkgd = NULL;
416 pkgd = match_pkg_by_pattern(d, pkg);
418 pkgd = match_pkg_by_pkgver(d, pkg);
420 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)