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)
40 xbps_object_t obj = NULL;
47 for (
unsigned int i = 0; i < xbps_array_count(array); i++) {
48 const char *pkgver = NULL;
49 char pkgname[XBPS_NAME_SIZE] = {0};
51 obj = xbps_array_get(array, i);
52 if (!xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
70 if (strcmp(str, pkgver) == 0) {
79 if (strcmp(pkgname, str) == 0) {
87 if (found && tt && (ttype != tt)) {
97xbps_dictionary_t HIDDEN
100 assert(xbps_object_type(a) == XBPS_TYPE_ARRAY);
103 return get_pkg_in_array(a, s, tt,
false);
106xbps_dictionary_t HIDDEN
107xbps_find_virtualpkg_in_array(
struct xbps_handle *xhp,
112 xbps_dictionary_t pkgd;
116 assert(xbps_object_type(a) == XBPS_TYPE_ARRAY);
119 if ((vpkg = vpkg_user_conf(xhp, s))) {
120 if ((pkgd = get_pkg_in_array(a, vpkg, tt,
true)))
124 return get_pkg_in_array(a, s, tt,
true);
127static xbps_dictionary_t
128match_pkg_by_pkgver(xbps_dictionary_t repod,
const char *p)
130 xbps_dictionary_t d = NULL;
131 const char *pkgver = NULL;
132 char pkgname[XBPS_NAME_SIZE] = {0};
144 d = xbps_dictionary_get(repod, pkgname);
149 if (!xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver)) {
154 if (strcmp(pkgver, p) != 0) {
162static xbps_dictionary_t
163match_pkg_by_pattern(xbps_dictionary_t repod,
const char *p)
165 xbps_dictionary_t d = NULL;
166 const char *pkgver = NULL;
167 char pkgname[XBPS_NAME_SIZE] = {0};
175 return match_pkg_by_pkgver(repod, p);
182 d = xbps_dictionary_get(repod, pkgname);
187 if (!xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver)) {
201vpkg_user_conf(
struct xbps_handle *xhp,
const char *vpkg)
203 char namebuf[XBPS_NAME_SIZE];
204 xbps_dictionary_t providers;
206 xbps_object_iterator_t iter;
207 const char *pkg = NULL;
210 enum { PKGPATTERN, PKGVER, PKGNAME } match;
226 providers = xbps_dictionary_get(xhp->vpkgd, pkgname);
230 iter = xbps_dictionary_iterator(providers);
233 while ((obj = xbps_object_iterator_next(iter))) {
235 char buf[XBPS_NAME_SIZE] = {0};
236 const char *vpkg_conf = NULL, *vpkgname = NULL;
238 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
239 rpkg = xbps_dictionary_get_keysym(providers, obj);
240 pkg = xbps_string_cstring_nocopy(rpkg);
248 vpkgname = vpkg_conf;
262 if (strcmp(buf, vpkgname) != 0) {
267 if (strcmp(vpkg, vpkgname) != 0) {
272 xbps_dbg_printf(
"%s: vpkg_conf %s pkg %s vpkgname %s\n", __func__, vpkg_conf, pkg, vpkgname);
276 xbps_object_iterator_release(iter);
278 return found ? pkg : NULL;
281xbps_dictionary_t HIDDEN
282xbps_find_virtualpkg_in_conf(
struct xbps_handle *xhp,
286 xbps_object_iterator_t iter;
288 xbps_dictionary_t providers;
289 xbps_dictionary_t pkgd = NULL;
292 if (!xhp->vpkgd_conf)
295 providers = xbps_dictionary_get(xhp->vpkgd_conf, pkg);
299 iter = xbps_dictionary_iterator(providers);
302 while ((obj = xbps_object_iterator_next(iter))) {
304 char buf[XBPS_NAME_SIZE] = {0};
305 const char *vpkg_conf = NULL, *vpkgname = NULL;
307 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
308 rpkg = xbps_dictionary_get_keysym(providers, obj);
309 cur = xbps_string_cstring_nocopy(rpkg);
317 vpkgname = vpkg_conf;
326 char vpkgver[XBPS_NAME_SIZE +
sizeof(
"-999999_1")];
327 snprintf(buf,
sizeof(buf),
"%s-999999_1", vpkg_conf);
339 if (strcmp(buf, vpkgname)) {
343 if (strcmp(pkg, vpkgname)) {
347 xbps_dbg_printf(
"%s: found: %s %s %s\n", __func__, vpkg_conf, cur, vpkgname);
351 pkgd = match_pkg_by_pattern(d, cur);
353 pkgd = match_pkg_by_pkgver(d, cur);
355 pkgd = xbps_dictionary_get(d, cur);
358 xbps_object_iterator_release(iter);
363xbps_dictionary_t HIDDEN
364xbps_find_virtualpkg_in_dict(
struct xbps_handle *xhp,
369 xbps_object_iterator_t iter;
370 xbps_dictionary_t pkgd = NULL;
375 vpkg = vpkg_user_conf(xhp, pkg);
378 pkgd = match_pkg_by_pattern(d, vpkg);
380 pkgd = match_pkg_by_pkgver(d, vpkg);
382 pkgd = xbps_dictionary_get(d, vpkg);
388 iter = xbps_dictionary_iterator(d);
391 while ((obj = xbps_object_iterator_next(iter))) {
392 pkgd = xbps_dictionary_get_keysym(d, obj);
394 xbps_object_iterator_release(iter);
398 xbps_object_iterator_release(iter);
403xbps_dictionary_t HIDDEN
404xbps_find_pkg_in_dict(xbps_dictionary_t d,
const char *pkg)
406 xbps_dictionary_t pkgd = NULL;
409 pkgd = match_pkg_by_pattern(d, pkg);
411 pkgd = match_pkg_by_pkgver(d, pkg);
413 pkgd = xbps_dictionary_get(d, pkg);
Generic XBPS structure handler for initialization.
void xbps_error_printf(const char *fmt,...)
Prints error messages to stderr.
void xbps_dbg_printf(const char *fmt,...)
Prints debug messages to stderr.
void xbps_warn_printf(const char *fmt,...)
Prints warning messages to stderr.
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)
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)