35fc34e5e5bb000e9132447dae47cf9b878c2475
[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 "rpmmessages.h"        /* for fnpyKey */
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 extern int _rpmps_debug;
16
17 /**
18  * Raw data for an element of a problem set.
19  */
20 typedef struct rpmProblem_s * rpmProblem;
21
22 /**
23  * Transaction problems found while processing a transaction set/
24  */
25 typedef struct rpmps_s * rpmps;
26
27 typedef struct rpmpsi_s * rpmpsi;
28
29 /**
30  * Enumerate transaction set problem types.
31  */
32 typedef enum rpmProblemType_e {
33     RPMPROB_BADARCH,    /*!< package ... is for a different architecture */
34     RPMPROB_BADOS,      /*!< package ... is for a different operating system */
35     RPMPROB_PKG_INSTALLED, /*!< package ... is already installed */
36     RPMPROB_BADRELOCATE,/*!< path ... is not relocatable for package ... */
37     RPMPROB_REQUIRES,   /*!< package ... has unsatisfied Requires: ... */
38     RPMPROB_CONFLICT,   /*!< package ... has unsatisfied Conflicts: ... */
39     RPMPROB_NEW_FILE_CONFLICT, /*!< file ... conflicts between attemped installs of ... */
40     RPMPROB_FILE_CONFLICT,/*!< file ... from install of ... conflicts with file from package ... */
41     RPMPROB_OLDPACKAGE, /*!< package ... (which is newer than ...) is already installed */
42     RPMPROB_DISKSPACE,  /*!< installing package ... needs ... on the ... filesystem */
43     RPMPROB_DISKNODES,  /*!< installing package ... needs ... on the ... filesystem */
44  } rpmProblemType;
45
46 /**
47  */
48 struct rpmProblem_s {
49     char * pkgNEVR;
50     char * altNEVR;
51     fnpyKey key;
52     rpmProblemType type;
53     int ignoreProblem;
54     char * str1;
55     unsigned long ulong1;
56 };
57
58 /**
59  */
60 struct rpmps_s {
61     int numProblems;            /*!< Current probs array size. */
62     int numProblemsAlloced;     /*!< Allocated probs array size. */
63     rpmProblem probs;           /*!< Array of specific problems. */
64     int nrefs;                  /*!< Reference count. */
65 };
66
67 struct rpmpsi_s {
68     size_t ix;
69     rpmps ps;
70 };
71
72 /**
73  * Return formatted string representation of a problem.
74  * @param prob          rpm problem
75  * @return              formatted string (malloc'd)
76  */
77 extern const char * rpmProblemString(const rpmProblem prob);
78
79 /**
80  * Unreference a problem set instance.
81  * @param ps            problem set
82  * @param msg
83  * @return              problem set
84  */
85 rpmps rpmpsUnlink (rpmps ps,
86                 const char * msg);
87
88 /** @todo Remove debugging entry from the ABI. */
89 rpmps XrpmpsUnlink (rpmps ps,
90                 const char * msg, const char * fn, unsigned ln);
91 #define rpmpsUnlink(_ps, _msg)  XrpmpsUnlink(_ps, _msg, __FILE__, __LINE__)
92
93 /**
94  * Reference a problem set instance.
95  * @param ps            transaction set
96  * @param msg
97  * @return              new transaction set reference
98  */
99 rpmps rpmpsLink (rpmps ps, const char * msg);
100
101 /** @todo Remove debugging entry from the ABI. */
102 rpmps XrpmpsLink (rpmps ps,
103                 const char * msg, const char * fn, unsigned ln);
104 #define rpmpsLink(_ps, _msg)    XrpmpsLink(_ps, _msg, __FILE__, __LINE__)
105
106 /**
107  * Return number of problems in set.
108  * @param ps            problem set
109  * @return              number of problems
110  */
111 int rpmpsNumProblems(rpmps ps);
112
113 /**
114  * Initialize problem set iterator.
115  * @param ps            problem set
116  * @return              problem set iterator
117  */
118 rpmpsi rpmpsInitIterator(rpmps ps);
119
120 /**
121  * Destroy problem set iterator.
122  * @param psi           problem set iterator
123  * @return              problem set iterator (NULL)
124  */
125 rpmpsi rpmpsFreeIterator(rpmpsi psi);
126
127 /**
128  * Return next problem set iterator index
129  * @param psi           problem set iterator
130  * @return              iterator index, -1 on termination
131  */
132 int rpmpsNextIterator(rpmpsi psi);
133
134 /**
135  * Return current problem from problem set
136  * @param psi           problem set iterator
137  * @return              current rpmProblem 
138  */
139 rpmProblem rpmpsProblem(rpmpsi psi);
140
141 /**
142  * Create a problem set.
143  * @return              new problem set
144  */
145 rpmps rpmpsCreate(void);
146
147 /**
148  * Destroy a problem set.
149  * @param ps            problem set
150  * @return              NULL always
151  */
152 rpmps rpmpsFree(rpmps ps);
153
154 /**
155  * Print problems to file handle.
156  * @param fp            file handle (NULL uses stderr)
157  * @param ps            problem set
158  */
159 void rpmpsPrint(FILE *fp, rpmps ps);
160
161 /**
162  * Append a problem to current set of problems.
163  * @param ps            problem set
164  * @param type          type of problem
165  * @param pkgNEVR       package name
166  * @param key           filename or python object address
167  * @param dn            directory name
168  * @param bn            file base name
169  * @param altNEVR       related (e.g. through a dependency) package name
170  * @param ulong1        generic pointer/long attribute
171  */
172 void rpmpsAppend(rpmps ps, rpmProblemType type,
173                 const char * pkgNEVR,
174                 fnpyKey key,
175                 const char * dn, const char * bn,
176                 const char * altNEVR,
177                 unsigned long ulong1);
178
179 /**
180  * Filter a problem set.
181  *
182  * As the problem sets are generated in an order solely dependent
183  * on the ordering of the packages in the transaction, and that
184  * ordering can't be changed, the problem sets must be parallel to
185  * one another. Additionally, the filter set must be a subset of the
186  * target set, given the operations available on transaction set.
187  * This is good, as it lets us perform this trim in linear time, rather
188  * then logarithmic or quadratic.
189  *
190  * @param ps            problem set
191  * @param filter        problem filter (or NULL)
192  * @return              0 no problems, 1 if problems remain
193  */
194 int rpmpsTrim(rpmps ps, rpmps filter);
195
196 #ifdef __cplusplus
197 }
198 #endif
199
200 #endif  /* H_RPMPS */