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