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