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) {
78 if (strcmp(pkgname, str) == 0) {
86 if (found && tt && (ttype != tt)) {
96xbps_dictionary_t HIDDEN
99 assert(xbps_object_type(a) == XBPS_TYPE_ARRAY);
102 return get_pkg_in_array(a, s, tt,
false);
105xbps_dictionary_t HIDDEN
106xbps_find_virtualpkg_in_array(
struct xbps_handle *xhp,
111 xbps_dictionary_t pkgd;
115 assert(xbps_object_type(a) == XBPS_TYPE_ARRAY);
118 if ((vpkg = vpkg_user_conf(xhp, s))) {
119 if ((pkgd = get_pkg_in_array(a, vpkg, tt,
true)))
123 return get_pkg_in_array(a, s, tt,
true);
126static xbps_dictionary_t
127match_pkg_by_pkgver(xbps_dictionary_t repod,
const char *p)
129 xbps_dictionary_t d = NULL;
130 const char *pkgver = NULL;
131 char pkgname[XBPS_NAME_SIZE] = {0};
143 d = xbps_dictionary_get(repod, pkgname);
148 if (!xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver)) {
153 if (strcmp(pkgver, p) != 0) {
161static xbps_dictionary_t
162match_pkg_by_pattern(xbps_dictionary_t repod,
const char *p)
164 xbps_dictionary_t d = NULL;
165 const char *pkgver = NULL;
166 char pkgname[XBPS_NAME_SIZE] = {0};
174 return match_pkg_by_pkgver(repod, p);
181 d = xbps_dictionary_get(repod, pkgname);
186 if (!xbps_dictionary_get_cstring_nocopy(d,
"pkgver", &pkgver)) {
200vpkg_user_conf(
struct xbps_handle *xhp,
const char *vpkg)
202 char namebuf[XBPS_NAME_SIZE];
203 xbps_dictionary_t providers;
205 xbps_object_iterator_t iter;
206 const char *pkg = NULL;
209 enum { PKGPATTERN, PKGVER, PKGNAME } match;
225 providers = xbps_dictionary_get(xhp->vpkgd, pkgname);
229 iter = xbps_dictionary_iterator(providers);
232 while ((obj = xbps_object_iterator_next(iter))) {
234 char buf[XBPS_NAME_SIZE] = {0};
235 const char *vpkg_conf = NULL, *vpkgname = NULL;
237 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
238 rpkg = xbps_dictionary_get_keysym(providers, obj);
239 pkg = xbps_string_cstring_nocopy(rpkg);
246 vpkgname = vpkg_conf;
260 if (strcmp(buf, vpkgname) != 0) {
265 if (strcmp(vpkg, vpkgname) != 0) {
270 xbps_dbg_printf(
"%s: vpkg_conf %s pkg %s vpkgname %s\n", __func__, vpkg_conf, pkg, vpkgname);
274 xbps_object_iterator_release(iter);
276 return found ? pkg : NULL;
279xbps_dictionary_t HIDDEN
280xbps_find_virtualpkg_in_conf(
struct xbps_handle *xhp,
284 xbps_object_iterator_t iter;
286 xbps_dictionary_t providers;
287 xbps_dictionary_t pkgd = NULL;
290 if (!xhp->vpkgd_conf)
293 providers = xbps_dictionary_get(xhp->vpkgd_conf, pkg);
297 iter = xbps_dictionary_iterator(providers);
300 while ((obj = xbps_object_iterator_next(iter))) {
302 char buf[XBPS_NAME_SIZE] = {0};
303 const char *vpkg_conf = NULL, *vpkgname = NULL;
305 vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
306 rpkg = xbps_dictionary_get_keysym(providers, obj);
307 cur = xbps_string_cstring_nocopy(rpkg);
314 vpkgname = vpkg_conf;
323 char vpkgver[XBPS_NAME_SIZE +
sizeof(
"-999999_1")];
324 snprintf(buf,
sizeof(buf),
"%s-999999_1", vpkg_conf);
335 if (strcmp(buf, vpkgname)) {
339 if (strcmp(pkg, vpkgname)) {
343 xbps_dbg_printf(
"%s: found: %s %s %s\n", __func__, vpkg_conf, cur, vpkgname);
347 pkgd = match_pkg_by_pattern(d, cur);
349 pkgd = match_pkg_by_pkgver(d, cur);
351 pkgd = xbps_dictionary_get(d, cur);
354 xbps_object_iterator_release(iter);
359xbps_dictionary_t HIDDEN
360xbps_find_virtualpkg_in_dict(
struct xbps_handle *xhp,
365 xbps_object_iterator_t iter;
366 xbps_dictionary_t pkgd = NULL;
371 vpkg = vpkg_user_conf(xhp, pkg);
374 pkgd = match_pkg_by_pattern(d, vpkg);
376 pkgd = match_pkg_by_pkgver(d, vpkg);
378 pkgd = xbps_dictionary_get(d, vpkg);
384 iter = xbps_dictionary_iterator(d);
387 while ((obj = xbps_object_iterator_next(iter))) {
388 pkgd = xbps_dictionary_get_keysym(d, obj);
390 xbps_object_iterator_release(iter);
394 xbps_object_iterator_release(iter);
399xbps_dictionary_t HIDDEN
400xbps_find_pkg_in_dict(xbps_dictionary_t d,
const char *pkg)
402 xbps_dictionary_t pkgd = NULL;
405 pkgd = match_pkg_by_pattern(d, pkg);
407 pkgd = match_pkg_by_pkgver(d, pkg);
409 pkgd = xbps_dictionary_get(d, pkg);
Generic XBPS structure handler for initialization.
#define xbps_unreachable()
Log and abort for code that should be unreachable.
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)