dpkg (1.18.25) stretch; urgency=medium
[dpkg] / lib / dpkg / pkg-spec.h
1 /*
2 * libdpkg - Debian packaging suite library routines
3 * pkg-spec.h - primitives for pkg specifier handling
4 *
5 * Copyright © 2011 Linaro Limited
6 * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
7 * Copyright © 2011-2014 Guillem Jover <guillem@debian.org>
8 *
9 * This is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23 #ifndef LIBDPKG_PKG_SPEC_H
24 #define LIBDPKG_PKG_SPEC_H
25
26 #include <stdbool.h>
27
28 #include <dpkg/macros.h>
29 #include <dpkg/dpkg-db.h>
30 #include <dpkg/error.h>
31 #include <dpkg/arch.h>
32
33 DPKG_BEGIN_DECLS
34
35 /**
36 * @defgroup pkg-spec Package specifiers
37 * @ingroup dpkg-public
38 * @{
39 */
40
41 enum pkg_spec_flags {
42 /** Recognize glob patterns. */
43 PKG_SPEC_PATTERNS = DPKG_BIT(0),
44
45 /* How to consider the lack of an arch qualifier. */
46 PKG_SPEC_ARCH_SINGLE = DPKG_BIT(8),
47 PKG_SPEC_ARCH_WILDCARD = DPKG_BIT(9),
48 PKG_SPEC_ARCH_MASK = 0xff00,
49 };
50
51 struct pkg_spec {
52 char *name;
53 const struct dpkg_arch *arch;
54
55 enum pkg_spec_flags flags;
56
57 /* Members below are private state. */
58
59 bool name_is_pattern;
60 bool arch_is_pattern;
61
62 /** Used for the pkg_db iterator. */
63 struct pkgiterator *pkg_iter;
64 /** Used for the pkgset iterator. */
65 struct pkginfo *pkg_next;
66 };
67
68 void pkg_spec_init(struct pkg_spec *ps, enum pkg_spec_flags flags);
69 void pkg_spec_destroy(struct pkg_spec *ps);
70
71 const char *pkg_spec_is_illegal(struct pkg_spec *ps);
72
73 const char *pkg_spec_set(struct pkg_spec *ps,
74 const char *pkgname, const char *archname);
75 const char *pkg_spec_parse(struct pkg_spec *ps, const char *str);
76 bool pkg_spec_match_pkg(struct pkg_spec *ps,
77 struct pkginfo *pkg, struct pkgbin *pkgbin);
78
79 struct pkginfo *pkg_spec_parse_pkg(const char *str, struct dpkg_error *err);
80 struct pkginfo *pkg_spec_find_pkg(const char *pkgname, const char *archname,
81 struct dpkg_error *err);
82
83 void pkg_spec_iter_init(struct pkg_spec *ps);
84 struct pkginfo *pkg_spec_iter_next_pkg(struct pkg_spec *ps);
85 void pkg_spec_iter_destroy(struct pkg_spec *ps);
86
87 /** @} */
88
89 DPKG_END_DECLS
90
91 #endif