Remove splint tags.
[platform/upstream/rpm.git] / lib / rpmte.h
1 #ifndef H_RPMTE
2 #define H_RPMTE
3
4 /** \ingroup rpmts rpmte
5  * \file lib/rpmte.h
6  * Structures used for an "rpmte" transaction element.
7  */
8
9 /**
10  */
11 extern int _rpmte_debug;
12
13 /**
14  * Transaction element ordering chain linkage.
15  */
16 typedef struct tsortInfo_s *            tsortInfo;
17
18 /**
19  * Transaction element iterator.
20  */
21 typedef struct rpmtsi_s *               rpmtsi;
22
23 /** \ingroup rpmte
24  * Transaction element type.
25  */
26 typedef enum rpmElementType_e {
27     TR_ADDED            = (1 << 0),     /*!< Package will be installed. */
28     TR_REMOVED          = (1 << 1)      /*!< Package will be removed. */
29 } rpmElementType;
30
31 #if     defined(_RPMTE_INTERNAL)
32 /** \ingroup rpmte
33  * Dependncy ordering information.
34  */
35 struct tsortInfo_s {
36     union {
37         int     count;
38         rpmte   suc;
39     } tsi_u;
40 #define tsi_count       tsi_u.count
41 #define tsi_suc         tsi_u.suc
42     struct tsortInfo_s * tsi_next;
43     rpmte tsi_chain;
44     int         tsi_reqx;
45     int         tsi_qcnt;
46 };
47
48 /** \ingroup rpmte
49  * A single package instance to be installed/removed atomically.
50  */
51 struct rpmte_s {
52     rpmElementType type;        /*!< Package disposition (installed/removed). */
53
54     Header h;                   /*!< Package header. */
55     const char * NEVR;          /*!< Package name-version-release. */
56     const char * NEVRA;         /*!< Package name-version-release.arch. */
57     const char * name;          /*!< Name: */
58     char * epoch;
59     char * version;             /*!< Version: */
60     char * release;             /*!< Release: */
61     const char * arch;          /*!< Architecture hint. */
62     const char * os;            /*!< Operating system hint. */
63     int archScore;              /*!< (TR_ADDED) Arch score. */
64     int osScore;                /*!< (TR_ADDED) Os score. */
65     int isSource;               /*!< (TR_ADDED) source rpm? */
66
67     rpmte parent;               /*!< Parent transaction element. */
68     int degree;                 /*!< No. of immediate children. */
69     int npreds;                 /*!< No. of predecessors. */
70     int tree;                   /*!< Tree index. */
71     int depth;                  /*!< Depth in dependency tree. */
72     int breadth;                /*!< Breadth in dependency tree. */
73     unsigned int db_instance;   /*!< Database Instance after add */
74     tsortInfo tsi;              /*!< Dependency ordering chains. */
75
76     rpmds this;                 /*!< This package's provided NEVR. */
77     rpmds provides;             /*!< Provides: dependencies. */
78     rpmds requires;             /*!< Requires: dependencies. */
79     rpmds conflicts;            /*!< Conflicts: dependencies. */
80     rpmds obsoletes;            /*!< Obsoletes: dependencies. */
81     rpmfi fi;                   /*!< File information. */
82
83     uint_32 color;              /*!< Color bit(s) from package dependencies. */
84     uint_32 pkgFileSize;        /*!< No. of bytes in package file (approx). */
85
86     fnpyKey key;                /*!< (TR_ADDED) Retrieval key. */
87     rpmRelocation * relocs;     /*!< (TR_ADDED) Payload file relocations. */
88     int nrelocs;                /*!< (TR_ADDED) No. of relocations. */
89     int autorelocatex;          /*!< (TR_ADDED) Auto relocation entry index. */
90     FD_t fd;                    /*!< (TR_ADDED) Payload file descriptor. */
91
92     union {
93         alKey addedKey;
94         struct {
95             alKey dependsOnKey;
96             int dboffset;
97         } removed;
98     } u;
99
100 };
101
102 /**
103  * Iterator across transaction elements, forward on install, backward on erase.
104  */
105 struct rpmtsi_s {
106     rpmts ts;           /*!< transaction set. */
107     int reverse;        /*!< reversed traversal? */
108     int ocsave;         /*!< last returned iterator index. */
109     int oc;             /*!< iterator index. */
110 };
111
112 #endif  /* _RPMTE_INTERNAL */
113
114 #ifdef __cplusplus
115 extern "C" {
116 #endif
117
118 /**
119  * Destroy a transaction element.
120  * @param te            transaction element
121  * @return              NULL always
122  */
123 rpmte rpmteFree(rpmte te);
124
125 /**
126  * Create a transaction element.
127  * @param ts            transaction set
128  * @param h             header
129  * @param type          TR_ADDED/TR_REMOVED
130  * @param key           (TR_ADDED) package retrieval key (e.g. file name)
131  * @param relocs        (TR_ADDED) package file relocations
132  * @param dboffset      (TR_REMOVED) rpmdb instance
133  * @param pkgKey        associated added package (if any)
134  * @return              new transaction element
135  */
136 rpmte rpmteNew(const rpmts ts, Header h, rpmElementType type,
137                 fnpyKey key,
138                 rpmRelocation * relocs,
139                 int dboffset,
140                 alKey pkgKey);
141
142 /**
143  * Retrieve header from transaction element.
144  * @param te            transaction element
145  * @return              header
146  */
147 extern Header rpmteHeader(rpmte te);
148
149 /**
150  * Save header into transaction element.
151  * @param te            transaction element
152  * @param h             header
153  * @return              NULL always
154  */
155 extern Header rpmteSetHeader(rpmte te, Header h);
156
157 /**
158  * Retrieve type of transaction element.
159  * @param te            transaction element
160  * @return              type
161  */
162 rpmElementType rpmteType(rpmte te);
163
164 /**
165  * Retrieve name string of transaction element.
166  * @param te            transaction element
167  * @return              name string
168  */
169 extern const char * rpmteN(rpmte te);
170
171 /**
172  * Retrieve epoch string of transaction element.
173  * @param te            transaction element
174  * @return              epoch string
175  */
176 extern const char * rpmteE(rpmte te);
177
178 /**
179  * Retrieve version string of transaction element.
180  * @param te            transaction element
181  * @return              version string
182  */
183 extern const char * rpmteV(rpmte te);
184
185 /**
186  * Retrieve release string of transaction element.
187  * @param te            transaction element
188  * @return              release string
189  */
190 extern const char * rpmteR(rpmte te);
191
192 /**
193  * Retrieve arch string of transaction element.
194  * @param te            transaction element
195  * @return              arch string
196  */
197 extern const char * rpmteA(rpmte te);
198
199 /**
200  * Retrieve os string of transaction element.
201  * @param te            transaction element
202  * @return              os string
203  */
204 extern const char * rpmteO(rpmte te);
205
206 /**
207  * Retrieve isSource attribute of transaction element.
208  * @param te            transaction element
209  * @return              isSource attribute
210  */
211 extern int rpmteIsSource(rpmte te);
212
213 /**
214  * Retrieve color bits of transaction element.
215  * @param te            transaction element
216  * @return              color bits
217  */
218 uint_32 rpmteColor(rpmte te);
219
220 /**
221  * Set color bits of transaction element.
222  * @param te            transaction element
223  * @param color         new color bits
224  * @return              previous color bits
225  */
226 uint_32 rpmteSetColor(rpmte te, uint_32 color);
227
228 /**
229  * Retrieve last instance installed to the database.
230  * @param te            transaction element
231  * @return              last install instance.
232  */
233 unsigned int rpmteDBInstance(rpmte te);
234
235 /**
236  * Set last instance installed to the database.
237  * @param te            transaction element
238  * @param instance      Database instance of last install element.
239  * @return              last install instance.
240  */
241 void rpmteSetDBInstance(rpmte te, unsigned int instance);
242
243 /**
244  * Retrieve size in bytes of package file.
245  * @todo Signature header is estimated at 256b.
246  * @param te            transaction element
247  * @return              size in bytes of package file.
248  */
249 uint_32 rpmtePkgFileSize(rpmte te);
250
251 /**
252  * Retrieve dependency tree depth of transaction element.
253  * @param te            transaction element
254  * @return              depth
255  */
256 int rpmteDepth(rpmte te);
257
258 /**
259  * Set dependency tree depth of transaction element.
260  * @param te            transaction element
261  * @param ndepth        new depth
262  * @return              previous depth
263  */
264 int rpmteSetDepth(rpmte te, int ndepth);
265
266 /**
267  * Retrieve dependency tree breadth of transaction element.
268  * @param te            transaction element
269  * @return              breadth
270  */
271 int rpmteBreadth(rpmte te);
272
273 /**
274  * Set dependency tree breadth of transaction element.
275  * @param te            transaction element
276  * @param nbreadth      new breadth
277  * @return              previous breadth
278  */
279 int rpmteSetBreadth(rpmte te, int nbreadth);
280
281 /**
282  * Retrieve tsort no. of predecessors of transaction element.
283  * @param te            transaction element
284  * @return              no. of predecessors
285  */
286 int rpmteNpreds(rpmte te);
287
288 /**
289  * Set tsort no. of predecessors of transaction element.
290  * @param te            transaction element
291  * @param npreds        new no. of predecessors
292  * @return              previous no. of predecessors
293  */
294 int rpmteSetNpreds(rpmte te, int npreds);
295
296 /**
297  * Retrieve tree index of transaction element.
298  * @param te            transaction element
299  * @return              tree index
300  */
301 int rpmteTree(rpmte te);
302
303 /**
304  * Set tree index of transaction element.
305  * @param te            transaction element
306  * @param ntree         new tree index
307  * @return              previous tree index
308  */
309 int rpmteSetTree(rpmte te, int ntree);
310
311 /**
312  * Retrieve parent transaction element.
313  * @param te            transaction element
314  * @return              parent transaction element
315  */
316 rpmte rpmteParent(rpmte te);
317
318 /**
319  * Set parent transaction element.
320  * @param te            transaction element
321  * @param pte           new parent transaction element
322  * @return              previous parent transaction element
323  */
324 rpmte rpmteSetParent(rpmte te, rpmte pte);
325
326 /**
327  * Retrieve number of children of transaction element.
328  * @param te            transaction element
329  * @return              tree index
330  */
331 int rpmteDegree(rpmte te);
332
333 /**
334  * Set number of children of transaction element.
335  * @param te            transaction element
336  * @param ndegree       new number of children
337  * @return              previous number of children
338  */
339 int rpmteSetDegree(rpmte te, int ndegree);
340
341 /**
342  * Retrieve tsort info for transaction element.
343  * @param te            transaction element
344  * @return              tsort info
345  */
346 tsortInfo rpmteTSI(rpmte te);
347
348 /**
349  * Destroy tsort info of transaction element.
350  * @param te            transaction element
351  */
352 void rpmteFreeTSI(rpmte te);
353
354 /**
355  * Initialize tsort info of transaction element.
356  * @param te            transaction element
357  */
358 void rpmteNewTSI(rpmte te);
359
360 /**
361  * Destroy dependency set info of transaction element.
362  * @param te            transaction element
363  */
364 void rpmteCleanDS(rpmte te);
365
366 /**
367  * Retrieve pkgKey of TR_ADDED transaction element.
368  * @param te            transaction element
369  * @return              pkgKey
370  */
371 alKey rpmteAddedKey(rpmte te);
372
373 /**
374  * Set pkgKey of TR_ADDED transaction element.
375  * @param te            transaction element
376  * @param npkgKey       new pkgKey
377  * @return              previous pkgKey
378  */
379 alKey rpmteSetAddedKey(rpmte te,
380                 alKey npkgKey);
381
382 /**
383  * Retrieve dependent pkgKey of TR_REMOVED transaction element.
384  * @param te            transaction element
385  * @return              dependent pkgKey
386  */
387 alKey rpmteDependsOnKey(rpmte te);
388
389 /**
390  * Retrieve rpmdb instance of TR_REMOVED transaction element.
391  * @param te            transaction element
392  * @return              rpmdb instance
393  */
394 int rpmteDBOffset(rpmte te);
395
396 /**
397  * Retrieve name-version-release string from transaction element.
398  * @param te            transaction element
399  * @return              name-version-release string
400  */
401 extern const char * rpmteNEVR(rpmte te);
402
403 /**
404  * Retrieve name-version-release.arch string from transaction element.
405  * @param te            transaction element
406  * @return              name-version-release.arch string
407  */
408 extern const char * rpmteNEVRA(rpmte te);
409
410 /**
411  * Retrieve file handle from transaction element.
412  * @param te            transaction element
413  * @return              file handle
414  */
415 FD_t rpmteFd(rpmte te);
416
417 /**
418  * Retrieve key from transaction element.
419  * @param te            transaction element
420  * @return              key
421  */
422 fnpyKey rpmteKey(rpmte te);
423
424 /**
425  * Retrieve dependency tag set from transaction element.
426  * @param te            transaction element
427  * @param tag           dependency tag
428  * @return              dependency tag set
429  */
430 rpmds rpmteDS(rpmte te, rpmTag tag);
431
432 /**
433  * Retrieve file info tag set from transaction element.
434  * @param te            transaction element
435  * @param tag           file info tag (RPMTAG_BASENAMES)
436  * @return              file info tag set
437  */
438 rpmfi rpmteFI(rpmte te, rpmTag tag);
439
440 /**
441  * Calculate transaction element dependency colors/refs from file info.
442  * @param te            transaction element
443  * @param tag           dependency tag (RPMTAG_PROVIDENAME, RPMTAG_REQUIRENAME)
444  */
445 void rpmteColorDS(rpmte te, rpmTag tag);
446
447 /**
448  * Return transaction element index.
449  * @param tsi           transaction element iterator
450  * @return              transaction element index
451  */
452 int rpmtsiOc(rpmtsi tsi);
453
454 /**
455  * Destroy transaction element iterator.
456  * @param tsi           transaction element iterator
457  * @return              NULL always
458  */
459 rpmtsi rpmtsiFree(rpmtsi tsi);
460
461 /**
462  * Destroy transaction element iterator.
463  * @param tsi           transaction element iterator
464  * @param fn
465  * @param ln
466  * @return              NULL always
467  */
468 rpmtsi XrpmtsiFree(rpmtsi tsi,
469                 const char * fn, unsigned int ln);
470 #define rpmtsiFree(_tsi)        XrpmtsiFree(_tsi, __FILE__, __LINE__)
471
472 /**
473  * Create transaction element iterator.
474  * @param ts            transaction set
475  * @return              transaction element iterator
476  */
477 rpmtsi rpmtsiInit(rpmts ts);
478
479 /**
480  * Create transaction element iterator.
481  * @param ts            transaction set
482  * @param fn
483  * @param ln
484  * @return              transaction element iterator
485  */
486 rpmtsi XrpmtsiInit(rpmts ts,
487                 const char * fn, unsigned int ln);
488 #define rpmtsiInit(_ts)         XrpmtsiInit(_ts, __FILE__, __LINE__)
489
490 /**
491  * Return next transaction element of type.
492  * @param tsi           transaction element iterator
493  * @param type          transaction element type selector (0 for any)
494  * @return              next transaction element of type, NULL on termination
495  */
496 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type);
497
498 #ifdef __cplusplus
499 }
500 #endif
501
502 #endif  /* H_RPMTE */