2011-02-05 16:36:03 +05:30
|
|
|
/*-
|
2012-01-19 16:56:40 +05:30
|
|
|
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
2011-02-05 16:36:03 +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"
|
|
|
|
|
|
|
|
static prop_dictionary_t
|
2012-11-30 11:41:51 +05:30
|
|
|
get_pkg_in_array(prop_array_t array, const char *str, bool virtual)
|
2011-02-05 16:36:03 +05:30
|
|
|
{
|
|
|
|
prop_object_t obj = NULL;
|
2012-11-30 14:19:09 +05:30
|
|
|
prop_object_iterator_t iter;
|
2012-11-30 11:41:51 +05:30
|
|
|
const char *pkgver, *dpkgn;
|
|
|
|
bool found = false;
|
2012-06-05 02:52:33 +05:30
|
|
|
|
2012-11-30 14:19:09 +05:30
|
|
|
iter = prop_array_iterator(array);
|
|
|
|
assert(iter);
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2012-04-12 15:27:21 +05:30
|
|
|
if (virtual) {
|
|
|
|
/*
|
|
|
|
* Check if package pattern matches
|
|
|
|
* any virtual package version in dictionary.
|
|
|
|
*/
|
2012-11-30 11:41:51 +05:30
|
|
|
if (xbps_pkgpattern_version(str))
|
|
|
|
found = xbps_match_virtual_pkg_in_dict(obj, str, true);
|
|
|
|
else
|
|
|
|
found = xbps_match_virtual_pkg_in_dict(obj, str, false);
|
|
|
|
|
|
|
|
if (found)
|
2012-04-12 15:27:21 +05:30
|
|
|
break;
|
2012-11-30 11:41:51 +05:30
|
|
|
} else if (xbps_pkgpattern_version(str)) {
|
|
|
|
/* ,atch by pattern against pkgver */
|
2011-02-05 16:36:03 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"pkgver", &pkgver))
|
|
|
|
continue;
|
2012-11-30 11:41:51 +05:30
|
|
|
if (xbps_pkgpattern_match(pkgver, str)) {
|
|
|
|
found = true;
|
2011-02-05 16:36:03 +05:30
|
|
|
break;
|
2012-11-30 11:41:51 +05:30
|
|
|
}
|
|
|
|
} else if (xbps_pkg_version(str)) {
|
|
|
|
/* match by exact pkgver */
|
2011-02-05 16:36:03 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
2012-11-30 11:41:51 +05:30
|
|
|
"pkgver", &pkgver))
|
2011-02-05 16:36:03 +05:30
|
|
|
continue;
|
2012-11-30 11:41:51 +05:30
|
|
|
if (strcmp(str, pkgver) == 0) {
|
|
|
|
found = true;
|
2011-02-05 16:36:03 +05:30
|
|
|
break;
|
2012-06-05 14:28:39 +05:30
|
|
|
}
|
2012-11-30 11:41:51 +05:30
|
|
|
} else {
|
|
|
|
/* match by pkgname */
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"pkgname", &dpkgn))
|
|
|
|
continue;
|
|
|
|
if (strcmp(dpkgn, str) == 0) {
|
|
|
|
found = true;
|
2011-06-04 17:07:53 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|
2012-11-30 14:19:09 +05:30
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
return found ? obj : NULL;
|
2012-01-19 16:56:40 +05:30
|
|
|
}
|
|
|
|
|
2012-03-13 16:07:50 +05:30
|
|
|
prop_dictionary_t HIDDEN
|
2012-11-30 11:41:51 +05:30
|
|
|
xbps_find_pkg_in_array(prop_array_t a, const char *s)
|
2011-02-05 16:36:03 +05:30
|
|
|
{
|
2012-11-30 11:41:51 +05:30
|
|
|
assert(prop_object_type(a) == PROP_TYPE_ARRAY);
|
|
|
|
assert(s);
|
2011-07-15 21:52:58 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
return get_pkg_in_array(a, s, false);
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
prop_dictionary_t HIDDEN
|
|
|
|
xbps_find_virtualpkg_in_array(struct xbps_handle *x,
|
|
|
|
prop_array_t a,
|
|
|
|
const char *s)
|
2011-02-05 16:36:03 +05:30
|
|
|
{
|
2012-11-30 11:41:51 +05:30
|
|
|
prop_dictionary_t pkgd;
|
|
|
|
const char *vpkg;
|
|
|
|
bool bypattern = false;
|
2011-02-05 16:36:03 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
assert(x);
|
|
|
|
assert(prop_object_type(a) == PROP_TYPE_ARRAY);
|
|
|
|
assert(s);
|
2011-02-05 16:36:03 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
if (xbps_pkgpattern_version(s))
|
|
|
|
bypattern = true;
|
2011-02-05 16:36:03 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
if ((vpkg = vpkg_user_conf(x, s, bypattern))) {
|
|
|
|
if ((pkgd = get_pkg_in_array(a, vpkg, true)))
|
|
|
|
return pkgd;
|
2011-02-05 16:36:03 +05:30
|
|
|
}
|
2011-06-04 17:07:53 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
return get_pkg_in_array(a, s, true);
|
2011-07-15 21:52:58 +05:30
|
|
|
}
|