2011-07-20 00:37:04 +05:30
|
|
|
/*-
|
2015-01-10 11:56:23 +05:30
|
|
|
* Copyright (c) 2008-2015 Juan Romero Pardines.
|
2011-07-20 00:37:04 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file lib/plist_find.c
|
|
|
|
* @brief PropertyList generic routines
|
|
|
|
* @defgroup plist PropertyList generic functions
|
|
|
|
*
|
|
|
|
* These functions manipulate plist files and objects shared by almost
|
|
|
|
* all library functions.
|
|
|
|
*/
|
|
|
|
bool
|
2014-04-20 20:24:50 +05:30
|
|
|
xbps_match_virtual_pkg_in_array(xbps_array_t a, const char *str)
|
|
|
|
{
|
2020-01-18 17:20:59 +05:30
|
|
|
if (xbps_pkgpattern_version(str)) {
|
|
|
|
if (xbps_match_pkgdep_in_array(a, str) ||
|
|
|
|
xbps_match_pkgpattern_in_array(a, str))
|
2014-04-20 20:24:50 +05:30
|
|
|
return true;
|
2020-01-18 17:20:59 +05:30
|
|
|
} else if (xbps_pkg_version(str)) {
|
|
|
|
return xbps_match_string_in_array(a, str);
|
|
|
|
} else {
|
|
|
|
return xbps_match_pkgname_in_array(a, str);
|
|
|
|
}
|
2014-04-20 20:24:50 +05:30
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
xbps_match_virtual_pkg_in_dict(xbps_dictionary_t d, const char *str)
|
2011-07-20 00:37:04 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t provides;
|
2011-07-20 00:37:04 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
assert(xbps_object_type(d) == XBPS_TYPE_DICTIONARY);
|
2011-10-19 20:23:38 +05:30
|
|
|
|
2014-04-20 20:24:50 +05:30
|
|
|
if ((provides = xbps_dictionary_get(d, "provides")))
|
|
|
|
return xbps_match_virtual_pkg_in_array(provides, str);
|
|
|
|
|
|
|
|
return false;
|
2011-07-20 00:37:04 +05:30
|
|
|
}
|
|
|
|
|
2011-10-27 22:18:59 +05:30
|
|
|
bool
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_match_any_virtualpkg_in_rundeps(xbps_array_t rundeps,
|
|
|
|
xbps_array_t provides)
|
2011-10-27 22:18:59 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_t obj, obj2;
|
|
|
|
xbps_object_iterator_t iter, iter2;
|
2011-10-27 22:18:59 +05:30
|
|
|
const char *vpkgver, *pkgpattern;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
iter = xbps_array_iterator(provides);
|
2012-11-30 14:19:09 +05:30
|
|
|
assert(iter);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
vpkgver = xbps_string_cstring_nocopy(obj);
|
|
|
|
iter2 = xbps_array_iterator(rundeps);
|
2012-11-30 14:19:09 +05:30
|
|
|
assert(iter2);
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj2 = xbps_object_iterator_next(iter2))) {
|
|
|
|
pkgpattern = xbps_string_cstring_nocopy(obj2);
|
2012-06-05 14:28:39 +05:30
|
|
|
if (xbps_pkgpattern_match(vpkgver, pkgpattern)) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter2);
|
|
|
|
xbps_object_iterator_release(iter);
|
2012-03-11 21:56:41 +05:30
|
|
|
return true;
|
2012-06-05 14:28:39 +05:30
|
|
|
}
|
2011-10-27 22:18:59 +05:30
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter2);
|
2011-10-27 22:18:59 +05:30
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2012-11-30 14:19:09 +05:30
|
|
|
|
2012-03-11 21:56:41 +05:30
|
|
|
return false;
|
2011-10-27 22:18:59 +05:30
|
|
|
}
|
|
|
|
|
2011-07-20 00:37:04 +05:30
|
|
|
static bool
|
2013-06-20 13:56:12 +05:30
|
|
|
match_string_in_array(xbps_array_t array, const char *str, int mode)
|
2011-07-20 00:37:04 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_object_t obj;
|
2011-07-20 00:37:04 +05:30
|
|
|
const char *pkgdep;
|
2015-01-10 11:56:23 +05:30
|
|
|
char *curpkgname;
|
2011-07-20 00:37:04 +05:30
|
|
|
bool found = false;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
|
2011-07-20 00:37:04 +05:30
|
|
|
assert(str != NULL);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
iter = xbps_array_iterator(array);
|
2012-11-30 14:19:09 +05:30
|
|
|
assert(iter);
|
2011-07-20 00:37:04 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
2011-07-20 00:37:04 +05:30
|
|
|
if (mode == 0) {
|
|
|
|
/* match by string */
|
2013-06-20 13:56:12 +05:30
|
|
|
if (xbps_string_equals_cstring(obj, str)) {
|
2011-07-20 00:37:04 +05:30
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (mode == 1) {
|
2014-12-09 17:40:48 +05:30
|
|
|
/* match by pkgname against pkgver */
|
2013-06-20 13:56:12 +05:30
|
|
|
pkgdep = xbps_string_cstring_nocopy(obj);
|
2015-01-10 11:56:23 +05:30
|
|
|
curpkgname = xbps_pkg_name(pkgdep);
|
2011-07-20 00:37:04 +05:30
|
|
|
if (curpkgname == NULL)
|
|
|
|
break;
|
|
|
|
if (strcmp(curpkgname, str) == 0) {
|
|
|
|
free(curpkgname);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(curpkgname);
|
|
|
|
} else if (mode == 2) {
|
2014-12-09 17:40:48 +05:30
|
|
|
/* match by pkgver against pkgname */
|
|
|
|
pkgdep = xbps_string_cstring_nocopy(obj);
|
|
|
|
curpkgname = xbps_pkg_name(str);
|
|
|
|
if (curpkgname == NULL)
|
|
|
|
break;
|
|
|
|
if (strcmp(curpkgname, pkgdep) == 0) {
|
|
|
|
free(curpkgname);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(curpkgname);
|
|
|
|
} else if (mode == 3) {
|
2012-01-16 20:20:06 +05:30
|
|
|
/* match pkgpattern against pkgdep */
|
2013-06-20 13:56:12 +05:30
|
|
|
pkgdep = xbps_string_cstring_nocopy(obj);
|
2012-01-16 20:20:06 +05:30
|
|
|
if (xbps_pkgpattern_match(pkgdep, str)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-12-09 17:40:48 +05:30
|
|
|
} else if (mode == 4) {
|
2012-01-16 20:20:06 +05:30
|
|
|
/* match pkgdep against pkgpattern */
|
2013-06-20 13:56:12 +05:30
|
|
|
pkgdep = xbps_string_cstring_nocopy(obj);
|
2011-12-29 21:05:56 +05:30
|
|
|
if (xbps_pkgpattern_match(str, pkgdep)) {
|
2011-07-20 00:37:04 +05:30
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2011-07-20 00:37:04 +05:30
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_match_string_in_array(xbps_array_t array, const char *str)
|
2011-07-20 00:37:04 +05:30
|
|
|
{
|
|
|
|
return match_string_in_array(array, str, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_match_pkgname_in_array(xbps_array_t array, const char *pkgname)
|
2011-07-20 00:37:04 +05:30
|
|
|
{
|
|
|
|
return match_string_in_array(array, pkgname, 1);
|
|
|
|
}
|
|
|
|
|
2014-12-09 17:40:48 +05:30
|
|
|
bool
|
|
|
|
xbps_match_pkgver_in_array(xbps_array_t array, const char *pkgver)
|
|
|
|
{
|
|
|
|
return match_string_in_array(array, pkgver, 2);
|
|
|
|
}
|
|
|
|
|
2011-07-20 00:37:04 +05:30
|
|
|
bool
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_match_pkgpattern_in_array(xbps_array_t array, const char *pattern)
|
2011-07-20 00:37:04 +05:30
|
|
|
{
|
2014-12-09 17:40:48 +05:30
|
|
|
return match_string_in_array(array, pattern, 3);
|
2011-07-20 00:37:04 +05:30
|
|
|
}
|
2012-01-16 20:20:06 +05:30
|
|
|
|
|
|
|
bool
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_match_pkgdep_in_array(xbps_array_t array, const char *pkgver)
|
2012-01-16 20:20:06 +05:30
|
|
|
{
|
2014-12-09 17:40:48 +05:30
|
|
|
return match_string_in_array(array, pkgver, 4);
|
2012-01-16 20:20:06 +05:30
|
|
|
}
|