Add public function for testing problem equality
[platform/upstream/rpm.git] / lib / rpmps.h
1 #ifndef H_RPMPS
2 #define H_RPMPS
3
4 /** \ingroup rpmps
5  * \file lib/rpmps.h
6  * Structures and prototypes used for an "rpmps" problem set.
7  */
8
9 #include <stdio.h>
10 #include <rpm/rpmtypes.h>
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 /** \ingroup rpmps
17  * @todo Generalize filter mechanism.
18  */
19 typedef enum rpmprobFilterFlags_e {
20     RPMPROB_FILTER_NONE         = 0,
21     RPMPROB_FILTER_IGNOREOS     = (1 << 0),     /*!< from --ignoreos */
22     RPMPROB_FILTER_IGNOREARCH   = (1 << 1),     /*!< from --ignorearch */
23     RPMPROB_FILTER_REPLACEPKG   = (1 << 2),     /*!< from --replacepkgs */
24     RPMPROB_FILTER_FORCERELOCATE= (1 << 3),     /*!< from --badreloc */
25     RPMPROB_FILTER_REPLACENEWFILES= (1 << 4),   /*!< from --replacefiles */
26     RPMPROB_FILTER_REPLACEOLDFILES= (1 << 5),   /*!< from --replacefiles */
27     RPMPROB_FILTER_OLDPACKAGE   = (1 << 6),     /*!< from --oldpackage */
28     RPMPROB_FILTER_DISKSPACE    = (1 << 7),     /*!< from --ignoresize */
29     RPMPROB_FILTER_DISKNODES    = (1 << 8)      /*!< from --ignoresize */
30 } rpmprobFilterFlags;
31
32 /**
33  * Raw data for an element of a problem set.
34  */
35 typedef struct rpmProblem_s * rpmProblem;
36
37 /** \ingroup rpmps
38  * Problem set iterator
39  */
40 typedef struct rpmpsi_s * rpmpsi;
41
42 /** \ingroup rpmps
43  * Enumerate transaction set problem types.
44  */
45 typedef enum rpmProblemType_e {
46     RPMPROB_BADARCH,    /*!< package ... is for a different architecture */
47     RPMPROB_BADOS,      /*!< package ... is for a different operating system */
48     RPMPROB_PKG_INSTALLED, /*!< package ... is already installed */
49     RPMPROB_BADRELOCATE,/*!< path ... is not relocatable for package ... */
50     RPMPROB_REQUIRES,   /*!< package ... has unsatisfied Requires: ... */
51     RPMPROB_CONFLICT,   /*!< package ... has unsatisfied Conflicts: ... */
52     RPMPROB_NEW_FILE_CONFLICT, /*!< file ... conflicts between attemped installs of ... */
53     RPMPROB_FILE_CONFLICT,/*!< file ... from install of ... conflicts with file from package ... */
54     RPMPROB_OLDPACKAGE, /*!< package ... (which is newer than ...) is already installed */
55     RPMPROB_DISKSPACE,  /*!< installing package ... needs ... on the ... filesystem */
56     RPMPROB_DISKNODES,  /*!< installing package ... needs ... on the ... filesystem */
57     RPMPROB_OBSOLETES,  /*!< package ... is obsoleted by ... */
58  } rpmProblemType;
59
60 /** \ingroup rpmps
61  * Create a problem item.
62  * @param type          type of problem
63  * @param pkgNEVR       package name
64  * @param key           filename or python object address
65  * @param dn            directory name
66  * @param bn            file base name
67  * @param altNEVR       related (e.g. through a dependency) package name
68  * @param number        generic number attribute
69  * @return              rpmProblem
70  */
71 rpmProblem rpmProblemCreate(rpmProblemType type,
72                             const char * pkgNEVR,
73                             fnpyKey key,
74                             const char * dn, const char * bn,
75                             const char * altNEVR,
76                             uint64_t number);
77
78 /** \ingroup rpmps
79  * Destroy a problem item.
80  * @param prob          rpm problem
81  * @return              rpm problem (NULL)
82  */
83 rpmProblem rpmProblemFree(rpmProblem prob);
84
85 /** \ingroup rpmps
86  * Reference an rpmProblem instance
87  * @param prob          rpm problem
88  * @return              rpm problem
89  */
90 rpmProblem rpmProblemLink(rpmProblem prob);
91
92 /** \ingroup rpmps
93  * Unreference an rpmProblem instance
94  * @param prob          rpm problem
95  * @return              rpm problem
96  */
97 rpmProblem rpmProblemUnlink(rpmProblem prob);
98
99 /** \ingroup rpmps
100  * Compare two problems for equality.
101  * @param ap            1st problem
102  * @param bp            2nd problem
103  * @return              1 if the problems differ, 0 otherwise
104  */
105 int rpmProblemCompare(rpmProblem ap, rpmProblem bp);
106
107 /** \ingroup rpmps
108  * Return package NEVR
109  * @param prob          rpm problem
110  * @return              package NEVR
111  */
112 const char * rpmProblemGetPkgNEVR(const rpmProblem prob);
113 /** \ingroup rpmps
114  * Return related (e.g. through a dependency) package NEVR
115  * @param prob          rpm problem
116  * @return              related (e.g. through a dependency) package NEVR
117  */
118 const char * rpmProblemGetAltNEVR(const rpmProblem prob);
119
120 /** \ingroup rpmps
121  * Return type of problem (dependency, diskpace etc)
122  * @param prob          rpm problem
123  * @return              type of problem
124  */
125
126 rpmProblemType rpmProblemGetType(const rpmProblem prob);
127
128 /** \ingroup rpmps
129  * Return filename or python object address of a problem
130  * @param prob          rpm problem
131  * @return              filename or python object address
132  */
133 fnpyKey rpmProblemGetKey(const rpmProblem prob);
134
135 /** \ingroup rpmps
136  * Return a generic data string from a problem
137  * @param prob          rpm problem
138  * @return              a generic data string
139  * @todo                needs a better name
140  */
141 const char * rpmProblemGetStr(const rpmProblem prob);
142
143 /** \ingroup rpmps
144  * Return disk requirement (needed disk space / number of inodes)
145  * depending on problem type. On problem types other than RPMPROB_DISKSPACE
146  * and RPMPROB_DISKNODES return value is undefined.
147  * @param prob          rpm problem
148  * @return              disk requirement
149  */
150 rpm_loff_t rpmProblemGetDiskNeed(const rpmProblem prob);
151
152 /** \ingroup rpmps
153  * Return formatted string representation of a problem.
154  * @param prob          rpm problem
155  * @return              formatted string (malloc'd)
156  */
157 char * rpmProblemString(const rpmProblem prob);
158
159 /** \ingroup rpmps
160  * Unreference a problem set instance.
161  * @param ps            problem set
162  * @return              problem set
163  */
164 rpmps rpmpsUnlink (rpmps ps);
165
166 /** \ingroup rpmps
167  * Reference a problem set instance.
168  * @param ps            transaction set
169  * @return              new transaction set reference
170  */
171 rpmps rpmpsLink (rpmps ps);
172
173 /** \ingroup rpmps
174  * Return number of problems in set.
175  * @param ps            problem set
176  * @return              number of problems
177  */
178 int rpmpsNumProblems(rpmps ps);
179
180 /** \ingroup rpmps
181  * Initialize problem set iterator.
182  * @param ps            problem set
183  * @return              problem set iterator
184  */
185 rpmpsi rpmpsInitIterator(rpmps ps);
186
187 /** \ingroup rpmps
188  * Destroy problem set iterator.
189  * @param psi           problem set iterator
190  * @return              problem set iterator (NULL)
191  */
192 rpmpsi rpmpsFreeIterator(rpmpsi psi);
193
194 /** \ingroup rpmps
195  * Return next problem set iterator index
196  * @param psi           problem set iterator
197  * @return              iterator index, -1 on termination
198  */
199 int rpmpsNextIterator(rpmpsi psi);
200
201 /** \ingroup rpmps
202  * Return current problem from problem set
203  * @param psi           problem set iterator
204  * @return              current rpmProblem 
205  */
206 rpmProblem rpmpsGetProblem(rpmpsi psi);
207
208 /** \ingroup rpmps
209  * Create a problem set.
210  * @return              new problem set
211  */
212 rpmps rpmpsCreate(void);
213
214 /** \ingroup rpmps
215  * Destroy a problem set.
216  * @param ps            problem set
217  * @return              NULL always
218  */
219 rpmps rpmpsFree(rpmps ps);
220
221 /** \ingroup rpmps
222  * Print problems to file handle.
223  * @param fp            file handle (NULL uses stderr)
224  * @param ps            problem set
225  */
226 void rpmpsPrint(FILE *fp, rpmps ps);
227
228 /** \ingroup rpmps
229  * Append a problem to current set of problems.
230  * @param ps            problem set
231  * @param prob          rpmProblem 
232  */
233 void rpmpsAppendProblem(rpmps ps, rpmProblem prob);
234
235 /** \ingroup rpmps
236  * Append a problem to current set of problems.
237  * @param ps            problem set
238  * @param type          type of problem
239  * @param pkgNEVR       package name
240  * @param key           filename or python object address
241  * @param dn            directory name
242  * @param bn            file base name
243  * @param altNEVR       related (e.g. through a dependency) package name
244  * @param number        generic number attribute
245  */
246 void rpmpsAppend(rpmps ps, rpmProblemType type,
247                 const char * pkgNEVR,
248                 fnpyKey key,
249                 const char * dn, const char * bn,
250                 const char * altNEVR,
251                 uint64_t number);
252
253 /** \ingroup rpmps
254  * Filter a problem set.
255  *
256  * As the problem sets are generated in an order solely dependent
257  * on the ordering of the packages in the transaction, and that
258  * ordering can't be changed, the problem sets must be parallel to
259  * one another. Additionally, the filter set must be a subset of the
260  * target set, given the operations available on transaction set.
261  * This is good, as it lets us perform this trim in linear time, rather
262  * then logarithmic or quadratic.
263  *
264  * @param ps            problem set
265  * @param filter        problem filter (or NULL)
266  * @return              0 no problems, 1 if problems remain
267  */
268 int rpmpsTrim(rpmps ps, rpmps filter);
269
270 #ifdef __cplusplus
271 }
272 #endif
273
274 #endif  /* H_RPMPS */