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