1 /*
2 * Copyright (C) 2012-2019 Red Hat, Inc.
3 *
4 * Licensed under the GNU Lesser General Public License Version 2.1
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef HY_QUERY_H
22 #define HY_QUERY_H
23
24 #include <glib.h>
25 #include <stdbool.h>
26
27
28 G_BEGIN_DECLS
29
30 /* hawkey */
31 #include "dnf-sack.h"
32 #include "dnf-types.h"
33 #include "hy-types.h"
34
35 enum _hy_query_flags {
36 HY_IGNORE_EXCLUDES = 1 << 0
37 };
38
39 #define hy_autoquery __attribute__ ((cleanup(hy_query_autofree)))
40
41 void hy_query_apply(HyQuery q);
42 HyQuery hy_query_create(DnfSack *sack);
43 HyQuery hy_query_create_flags(DnfSack *sack, int flags);
44 HyQuery hy_query_from_nevra(HyNevra nevra, DnfSack *sack, bool icase);
45 void hy_query_free(HyQuery q);
46 Id query_get_index_item(HyQuery query, int index);
47 void hy_query_clear(HyQuery q);
48 HyQuery hy_query_clone(HyQuery q);
49 int hy_query_filter(HyQuery q, int keyname, int cmp_type, const char *match);
50 int hy_query_filter_empty(HyQuery q);
51 int hy_query_filter_in(HyQuery q, int keyname, int cmp_type,
52 const char **matches);
53 int hy_query_filter_num(HyQuery q, int keyname, int cmp_type,
54 int match);
55 int hy_query_filter_num_in(HyQuery q, int keyname, int cmp_type, int nmatches,
56 const int *matches);
57 int hy_query_filter_package_in(HyQuery q, int keyname, int cmp_type,
58 DnfPackageSet *pset);
59 int hy_query_filter_reldep(HyQuery q, int keyname, DnfReldep *reldep);
60 int hy_query_filter_reldep_in(HyQuery q, int keyname,
61 DnfReldepList *reldeplist);
62 int hy_query_filter_provides(HyQuery q, int cmp_type, const char *name,
63 const char *evr);
64 int hy_query_filter_provides_in(HyQuery q, char **reldep_strs);
65
66 /**
67 * Filter packages that are installed and have higher version than other not
68 * installed packages that are named same.
69 *
70 * NOTE: this does not guarantee packages filtered in this way are downgradable.
71 */
72 void hy_query_filter_downgradable(HyQuery q, int val);
73 /**
74 * Filter packages that are named same as an installed package but lower version.
75 *
76 * NOTE: this does not guarantee packages filtered in this way are installable.
77 */
78 void hy_query_filter_downgrades(HyQuery q, int val);
79 /**
80 * Filter packages that are installed and have lower version than other not
81 * installed packages that are named same.
82 *
83 * NOTE: this does not guarantee packages filtered in this way are upgradable.
84 */
85 void hy_query_filter_upgradable(HyQuery q, int val);
86 /**
87 * Filter packages that are named same as an installed package but higher version.
88 *
89 * NOTE: this does not guarantee packages filtered in this way are installable.
90 */
91 void hy_query_filter_upgrades(HyQuery q, int val);
92 void hy_query_filter_latest_per_arch(HyQuery q, int val);
93 void hy_query_filter_latest(HyQuery q, int val);
94
95 GPtrArray *hy_query_run(HyQuery q);
96 DnfPackageSet *hy_query_run_set(HyQuery q);
97
98 void hy_query_union(HyQuery q, HyQuery other);
99 void hy_query_intersection(HyQuery q, HyQuery other);
100 void hy_query_difference(HyQuery q, HyQuery other);
101 bool hy_query_is_empty(HyQuery query);
102 bool hy_query_is_applied(const HyQuery query);
103 const Map *hy_query_get_result(const HyQuery query);
104 DnfSack *hy_query_get_sack(HyQuery query);
105 void hy_add_filter_nevra_object(HyQuery query, HyNevra nevra, bool icase);
106 void hy_add_filter_extras(HyQuery query);
107 void hy_filter_recent(HyQuery query, const long unsigned int recent_limit);
108 void hy_filter_duplicated(HyQuery query);
109 GPtrArray * hy_query_get_advisory_pkgs(HyQuery query, int cmp_type);
110
111 static inline void
hy_query_autofree(void * v)112 hy_query_autofree (void *v)
113 {
114 HyQuery *pp = (HyQuery*)v;
115 HyQuery query = *pp;
116 if (query)
117 hy_query_free (query);
118 }
119
120 G_END_DECLS
121
122 #endif /* HY_QUERY_H */
123