Add options to populate transaction set while iterating.
[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@*/ /*@relnull@*/
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     int archScore;              /*!< (TR_ADDED) Arch score. */
81     int osScore;                /*!< (TR_ADDED) Os score. */
82     int isSource;               /*!< (TR_ADDED) source rpm? */
83
84     rpmte parent;               /*!< Parent transaction element. */
85     int degree;                 /*!< No. of immediate children. */
86     int depth;                  /*!< Max. depth in dependency tree. */
87     int npreds;                 /*!< No. of predecessors. */
88     int tree;                   /*!< Tree index. */
89     unsigned int db_instance;   /*!< Database Instance after add */
90 /*@owned@*/
91     tsortInfo tsi;              /*!< Dependency ordering chains. */
92
93 /*@refcounted@*/ /*@null@*/
94     rpmds this;                 /*!< This package's provided NEVR. */
95 /*@refcounted@*/ /*@null@*/
96     rpmds provides;             /*!< Provides: dependencies. */
97 /*@refcounted@*/ /*@null@*/
98     rpmds requires;             /*!< Requires: dependencies. */
99 /*@refcounted@*/ /*@null@*/
100     rpmds conflicts;            /*!< Conflicts: dependencies. */
101 /*@refcounted@*/ /*@null@*/
102     rpmds obsoletes;            /*!< Obsoletes: dependencies. */
103 /*@refcounted@*/ /*@null@*/
104     rpmfi fi;                   /*!< File information. */
105
106     uint_32 color;              /*!< Color bit(s) from package dependencies. */
107     uint_32 pkgFileSize;        /*!< No. of bytes in package file (approx). */
108
109 /*@exposed@*/ /*@dependent@*/ /*@null@*/
110     fnpyKey key;                /*!< (TR_ADDED) Retrieval key. */
111 /*@owned@*/ /*@null@*/
112     rpmRelocation * relocs;     /*!< (TR_ADDED) Payload file relocations. */
113     int nrelocs;                /*!< (TR_ADDED) No. of relocations. */
114     int autorelocatex;          /*!< (TR_ADDED) Auto relocation entry index. */
115 /*@refcounted@*/ /*@null@*/     
116     FD_t fd;                    /*!< (TR_ADDED) Payload file descriptor. */
117
118 /*@-fielduse@*/ /* LCL: confused by union? */
119     union {
120 /*@exposed@*/ /*@dependent@*/ /*@null@*/
121         alKey addedKey;
122         struct {
123 /*@exposed@*/ /*@dependent@*/ /*@null@*/
124             alKey dependsOnKey;
125             int dboffset;
126         } removed;
127     } u;
128 /*@=fielduse@*/
129
130 };
131
132 /**
133  * Iterator across transaction elements, forward on install, backward on erase.
134  */
135 struct rpmtsi_s {
136 /*@refcounted@*/
137     rpmts ts;           /*!< transaction set. */
138     int reverse;        /*!< reversed traversal? */
139     int ocsave;         /*!< last returned iterator index. */
140     int oc;             /*!< iterator index. */
141 };
142
143 #endif  /* _RPMTE_INTERNAL */
144
145 #ifdef __cplusplus
146 extern "C" {
147 #endif
148
149 /**
150  * Destroy a transaction element.
151  * @param te            transaction element
152  * @return              NULL always
153  */
154 /*@null@*/
155 rpmte rpmteFree(/*@only@*/ /*@null@*/ rpmte te)
156         /*@globals fileSystem @*/
157         /*@modifies te, fileSystem @*/;
158
159 /**
160  * Create a transaction element.
161  * @param ts            transaction set
162  * @param h             header
163  * @param type          TR_ADDED/TR_REMOVED
164  * @param key           (TR_ADDED) package retrieval key (e.g. file name)
165  * @param relocs        (TR_ADDED) package file relocations
166  * @param dboffset      (TR_REMOVED) rpmdb instance
167  * @param pkgKey        associated added package (if any)
168  * @return              new transaction element
169  */
170 /*@only@*/ /*@null@*/
171 rpmte rpmteNew(const rpmts ts, Header h, rpmElementType type,
172                 /*@exposed@*/ /*@dependent@*/ /*@null@*/ fnpyKey key,
173                 /*@null@*/ rpmRelocation * relocs,
174                 int dboffset,
175                 /*@exposed@*/ /*@dependent@*/ /*@null@*/ alKey pkgKey)
176         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
177         /*@modifies ts, h, rpmGlobalMacroContext, fileSystem, internalState @*/;
178
179 /**
180  * Retrieve type of transaction element.
181  * @param te            transaction element
182  * @return              type
183  */
184 rpmElementType rpmteType(rpmte te)
185         /*@*/;
186
187 /**
188  * Retrieve name string of transaction element.
189  * @param te            transaction element
190  * @return              name string
191  */
192 /*@observer@*/
193 extern const char * rpmteN(rpmte te)
194         /*@*/;
195
196 /**
197  * Retrieve epoch string of transaction element.
198  * @param te            transaction element
199  * @return              epoch string
200  */
201 /*@observer@*/ /*@null@*/
202 extern const char * rpmteE(rpmte te)
203         /*@*/;
204
205 /**
206  * Retrieve version string of transaction element.
207  * @param te            transaction element
208  * @return              version string
209  */
210 /*@observer@*/ /*@null@*/
211 extern const char * rpmteV(rpmte te)
212         /*@*/;
213
214 /**
215  * Retrieve release string of transaction element.
216  * @param te            transaction element
217  * @return              release string
218  */
219 /*@observer@*/ /*@null@*/
220 extern const char * rpmteR(rpmte te)
221         /*@*/;
222
223 /**
224  * Retrieve arch string of transaction element.
225  * @param te            transaction element
226  * @return              arch string
227  */
228 /*@observer@*/ /*@null@*/
229 extern const char * rpmteA(rpmte te)
230         /*@*/;
231
232 /**
233  * Retrieve os string of transaction element.
234  * @param te            transaction element
235  * @return              os string
236  */
237 /*@observer@*/ /*@null@*/
238 extern const char * rpmteO(rpmte te)
239         /*@*/;
240
241 /**
242  * Retrieve color bits of transaction element.
243  * @param te            transaction element
244  * @return              color bits
245  */
246 uint_32 rpmteColor(rpmte te)
247         /*@*/;
248
249 /**
250  * Set color bits of transaction element.
251  * @param te            transaction element
252  * @param color         new color bits
253  * @return              previous color bits
254  */
255 uint_32 rpmteSetColor(rpmte te, uint_32 color)
256         /*@modifies te @*/;
257
258 /**
259  * Retrieve last instance installed to the database.
260  * @param te            transaction element
261  * @return              last install instance.
262  */
263 unsigned int rpmteDBInstance(rpmte te)
264         /*@*/;
265
266 /**
267  * Set last instance installed to the database.
268  * @param te            transaction element
269  * @param instance      Database instance of last install element.
270  * @return              last install instance.
271  */
272 void rpmteSetDBInstance(rpmte te, unsigned int instance)
273         /*@modifies te @*/;
274
275 /**
276  * Retrieve size in bytes of package file.
277  * @todo Signature header is estimated at 256b.
278  * @param te            transaction element
279  * @return              size in bytes of package file.
280  */
281 uint_32 rpmtePkgFileSize(rpmte te)
282         /*@*/;
283
284 /**
285  * Retrieve tsort tree depth of transaction element.
286  * @param te            transaction element
287  * @return              depth
288  */
289 int rpmteDepth(rpmte te)
290         /*@*/;
291
292 /**
293  * Set tsort tree depth of transaction element.
294  * @param te            transaction element
295  * @param ndepth        new depth
296  * @return              previous depth
297  */
298 int rpmteSetDepth(rpmte te, int ndepth)
299         /*@modifies te @*/;
300
301 /**
302  * Retrieve tsort no. of predecessors of transaction element.
303  * @param te            transaction element
304  * @return              no. of predecessors
305  */
306 int rpmteNpreds(rpmte te)
307         /*@*/;
308
309 /**
310  * Set tsort no. of predecessors of transaction element.
311  * @param te            transaction element
312  * @param npreds        new no. of predecessors
313  * @return              previous no. of predecessors
314  */
315 int rpmteSetNpreds(rpmte te, int npreds)
316         /*@modifies te @*/;
317
318 /**
319  * Retrieve tree index of transaction element.
320  * @param te            transaction element
321  * @return              tree index
322  */
323 int rpmteTree(rpmte te)
324         /*@*/;
325
326 /**
327  * Set tree index of transaction element.
328  * @param te            transaction element
329  * @param ntree         new tree index
330  * @return              previous tree index
331  */
332 int rpmteSetTree(rpmte te, int ntree)
333         /*@modifies te @*/;
334
335 /**
336  * Retrieve parent transaction element.
337  * @param te            transaction element
338  * @return              parent transaction element
339  */
340 /*@observer@*/ /*@unused@*/
341 rpmte rpmteParent(rpmte te)
342         /*@*/;
343
344 /**
345  * Set parent transaction element.
346  * @param te            transaction element
347  * @param pte           new parent transaction element
348  * @return              previous parent transaction element
349  */
350 /*@null@*/
351 rpmte rpmteSetParent(rpmte te, rpmte pte)
352         /*@modifies te @*/;
353
354 /**
355  * Retrieve number of children of transaction element.
356  * @param te            transaction element
357  * @return              tree index
358  */
359 int rpmteDegree(rpmte te)
360         /*@*/;
361
362 /**
363  * Set number of children of transaction element.
364  * @param te            transaction element
365  * @param ndegree       new number of children
366  * @return              previous number of children
367  */
368 int rpmteSetDegree(rpmte te, int ndegree)
369         /*@modifies te @*/;
370
371 /**
372  * Retrieve tsort info for transaction element.
373  * @param te            transaction element
374  * @return              tsort info
375  */
376 tsortInfo rpmteTSI(rpmte te)
377         /*@*/;
378
379 /**
380  * Destroy tsort info of transaction element.
381  * @param te            transaction element
382  */
383 void rpmteFreeTSI(rpmte te)
384         /*@modifies te @*/;
385
386 /**
387  * Initialize tsort info of transaction element.
388  * @param te            transaction element
389  */
390 void rpmteNewTSI(rpmte te)
391         /*@modifies te @*/;
392
393 /**
394  * Destroy dependency set info of transaction element.
395  * @param te            transaction element
396  */
397 /*@unused@*/
398 void rpmteCleanDS(rpmte te)
399         /*@modifies te @*/;
400
401 /**
402  * Retrieve pkgKey of TR_ADDED transaction element.
403  * @param te            transaction element
404  * @return              pkgKey
405  */
406 /*@exposed@*/ /*@dependent@*/ /*@null@*/
407 alKey rpmteAddedKey(rpmte te)
408         /*@*/;
409
410 /**
411  * Set pkgKey of TR_ADDED transaction element.
412  * @param te            transaction element
413  * @param npkgKey       new pkgKey
414  * @return              previous pkgKey
415  */
416 /*@exposed@*/ /*@dependent@*/ /*@null@*/
417 alKey rpmteSetAddedKey(rpmte te,
418                 /*@exposed@*/ /*@dependent@*/ /*@null@*/ alKey npkgKey)
419         /*@modifies te @*/;
420
421 /**
422  * Retrieve dependent pkgKey of TR_REMOVED transaction element.
423  * @param te            transaction element
424  * @return              dependent pkgKey
425  */
426 /*@exposed@*/ /*@dependent@*/ /*@null@*/
427 alKey rpmteDependsOnKey(rpmte te)
428         /*@*/;
429
430 /**
431  * Retrieve rpmdb instance of TR_REMOVED transaction element.
432  * @param te            transaction element
433  * @return              rpmdb instance
434  */
435 int rpmteDBOffset(rpmte te)
436         /*@*/;
437
438 /**
439  * Retrieve name-version-release string from transaction element.
440  * @param te            transaction element
441  * @return              name-version-release string
442  */
443 /*@observer@*/
444 extern const char * rpmteNEVR(rpmte te)
445         /*@*/;
446
447 /**
448  * Retrieve name-version-release.arch string from transaction element.
449  * @param te            transaction element
450  * @return              name-version-release.arch string
451  */
452 /*@-exportlocal@*/
453 /*@observer@*/
454 extern const char * rpmteNEVRA(rpmte te)
455         /*@*/;
456 /*@=exportlocal@*/
457
458 /**
459  * Retrieve file handle from transaction element.
460  * @param te            transaction element
461  * @return              file handle
462  */
463 FD_t rpmteFd(rpmte te)
464         /*@*/;
465
466 /**
467  * Retrieve key from transaction element.
468  * @param te            transaction element
469  * @return              key
470  */
471 /*@exposed@*/
472 fnpyKey rpmteKey(rpmte te)
473         /*@*/;
474
475 /**
476  * Retrieve dependency tag set from transaction element.
477  * @param te            transaction element
478  * @param tag           dependency tag
479  * @return              dependency tag set
480  */
481 rpmds rpmteDS(rpmte te, rpmTag tag)
482         /*@*/;
483
484 /**
485  * Retrieve file info tag set from transaction element.
486  * @param te            transaction element
487  * @param tag           file info tag (RPMTAG_BASENAMES)
488  * @return              file info tag set
489  */
490 rpmfi rpmteFI(rpmte te, rpmTag tag)
491         /*@*/;
492
493 /**
494  * Calculate transaction element dependency colors/refs from file info.
495  * @param te            transaction element
496  * @param tag           dependency tag (RPMTAG_PROVIDENAME, RPMTAG_REQUIRENAME)
497  */
498 /*@-exportlocal@*/
499 void rpmteColorDS(rpmte te, rpmTag tag)
500         /*@modifies te @*/;
501 /*@=exportlocal@*/
502
503 /**
504  * Return transaction element index.
505  * @param tsi           transaction element iterator
506  * @return              transaction element index
507  */
508 int rpmtsiOc(rpmtsi tsi)
509         /*@*/;
510
511 /**
512  * Destroy transaction element iterator.
513  * @param tsi           transaction element iterator
514  * @return              NULL always
515  */
516 /*@unused@*/ /*@null@*/
517 rpmtsi rpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi)
518         /*@globals fileSystem @*/
519         /*@modifies fileSystem @*/;
520
521 /**
522  * Destroy transaction element iterator.
523  * @param tsi           transaction element iterator
524  * @param fn
525  * @param ln
526  * @return              NULL always
527  */
528 /*@null@*/
529 rpmtsi XrpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi,
530                 const char * fn, unsigned int ln)
531         /*@globals fileSystem @*/
532         /*@modifies fileSystem @*/;
533 #define rpmtsiFree(_tsi)        XrpmtsiFree(_tsi, __FILE__, __LINE__)
534
535 /**
536  * Create transaction element iterator.
537  * @param ts            transaction set
538  * @return              transaction element iterator
539  */
540 /*@unused@*/ /*@only@*/
541 rpmtsi rpmtsiInit(rpmts ts)
542         /*@modifies ts @*/;
543
544 /**
545  * Create transaction element iterator.
546  * @param ts            transaction set
547  * @param fn
548  * @param ln
549  * @return              transaction element iterator
550  */
551 /*@unused@*/ /*@only@*/
552 rpmtsi XrpmtsiInit(rpmts ts,
553                 const char * fn, unsigned int ln)
554         /*@modifies ts @*/;
555 #define rpmtsiInit(_ts)         XrpmtsiInit(_ts, __FILE__, __LINE__)
556
557 /**
558  * Return next transaction element of type.
559  * @param tsi           transaction element iterator
560  * @param type          transaction element type selector (0 for any)
561  * @return              next transaction element of type, NULL on termination
562  */
563 /*@dependent@*/ /*@null@*/
564 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
565         /*@modifies tsi @*/;
566
567 #ifdef __cplusplus
568 }
569 #endif
570
571 #endif  /* H_RPMTE */