Getter/setter methods for isSource and Header from rpmte.
[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 header from transaction element.
181  * @param te            transaction element
182  * @return              header
183  */
184 extern Header rpmteHeader(rpmte te)
185         /*@modifies te @*/;
186
187 /**
188  * Save header into transaction element.
189  * @param te            transaction element
190  * @param h             header
191  * @return              NULL always
192  */
193 extern Header rpmteSetHeader(rpmte te, Header h)
194         /*@modifies te, h @*/;
195
196 /**
197  * Retrieve type of transaction element.
198  * @param te            transaction element
199  * @return              type
200  */
201 rpmElementType rpmteType(rpmte te)
202         /*@*/;
203
204 /**
205  * Retrieve name string of transaction element.
206  * @param te            transaction element
207  * @return              name string
208  */
209 /*@observer@*/
210 extern const char * rpmteN(rpmte te)
211         /*@*/;
212
213 /**
214  * Retrieve epoch string of transaction element.
215  * @param te            transaction element
216  * @return              epoch string
217  */
218 /*@observer@*/ /*@null@*/
219 extern const char * rpmteE(rpmte te)
220         /*@*/;
221
222 /**
223  * Retrieve version string of transaction element.
224  * @param te            transaction element
225  * @return              version string
226  */
227 /*@observer@*/ /*@null@*/
228 extern const char * rpmteV(rpmte te)
229         /*@*/;
230
231 /**
232  * Retrieve release string of transaction element.
233  * @param te            transaction element
234  * @return              release string
235  */
236 /*@observer@*/ /*@null@*/
237 extern const char * rpmteR(rpmte te)
238         /*@*/;
239
240 /**
241  * Retrieve arch string of transaction element.
242  * @param te            transaction element
243  * @return              arch string
244  */
245 /*@observer@*/ /*@null@*/
246 extern const char * rpmteA(rpmte te)
247         /*@*/;
248
249 /**
250  * Retrieve os string of transaction element.
251  * @param te            transaction element
252  * @return              os string
253  */
254 /*@observer@*/ /*@null@*/
255 extern const char * rpmteO(rpmte te)
256         /*@*/;
257
258 /**
259  * Retrieve isSource attribute of transaction element.
260  * @param te            transaction element
261  * @return              isSource attribute
262  */
263 extern int rpmteIsSource(rpmte te)
264         /*@*/;
265
266 /**
267  * Retrieve color bits of transaction element.
268  * @param te            transaction element
269  * @return              color bits
270  */
271 uint_32 rpmteColor(rpmte te)
272         /*@*/;
273
274 /**
275  * Set color bits of transaction element.
276  * @param te            transaction element
277  * @param color         new color bits
278  * @return              previous color bits
279  */
280 uint_32 rpmteSetColor(rpmte te, uint_32 color)
281         /*@modifies te @*/;
282
283 /**
284  * Retrieve last instance installed to the database.
285  * @param te            transaction element
286  * @return              last install instance.
287  */
288 unsigned int rpmteDBInstance(rpmte te)
289         /*@*/;
290
291 /**
292  * Set last instance installed to the database.
293  * @param te            transaction element
294  * @param instance      Database instance of last install element.
295  * @return              last install instance.
296  */
297 void rpmteSetDBInstance(rpmte te, unsigned int instance)
298         /*@modifies te @*/;
299
300 /**
301  * Retrieve size in bytes of package file.
302  * @todo Signature header is estimated at 256b.
303  * @param te            transaction element
304  * @return              size in bytes of package file.
305  */
306 uint_32 rpmtePkgFileSize(rpmte te)
307         /*@*/;
308
309 /**
310  * Retrieve tsort tree depth of transaction element.
311  * @param te            transaction element
312  * @return              depth
313  */
314 int rpmteDepth(rpmte te)
315         /*@*/;
316
317 /**
318  * Set tsort tree depth of transaction element.
319  * @param te            transaction element
320  * @param ndepth        new depth
321  * @return              previous depth
322  */
323 int rpmteSetDepth(rpmte te, int ndepth)
324         /*@modifies te @*/;
325
326 /**
327  * Retrieve tsort no. of predecessors of transaction element.
328  * @param te            transaction element
329  * @return              no. of predecessors
330  */
331 int rpmteNpreds(rpmte te)
332         /*@*/;
333
334 /**
335  * Set tsort no. of predecessors of transaction element.
336  * @param te            transaction element
337  * @param npreds        new no. of predecessors
338  * @return              previous no. of predecessors
339  */
340 int rpmteSetNpreds(rpmte te, int npreds)
341         /*@modifies te @*/;
342
343 /**
344  * Retrieve tree index of transaction element.
345  * @param te            transaction element
346  * @return              tree index
347  */
348 int rpmteTree(rpmte te)
349         /*@*/;
350
351 /**
352  * Set tree index of transaction element.
353  * @param te            transaction element
354  * @param ntree         new tree index
355  * @return              previous tree index
356  */
357 int rpmteSetTree(rpmte te, int ntree)
358         /*@modifies te @*/;
359
360 /**
361  * Retrieve parent transaction element.
362  * @param te            transaction element
363  * @return              parent transaction element
364  */
365 /*@observer@*/ /*@unused@*/
366 rpmte rpmteParent(rpmte te)
367         /*@*/;
368
369 /**
370  * Set parent transaction element.
371  * @param te            transaction element
372  * @param pte           new parent transaction element
373  * @return              previous parent transaction element
374  */
375 /*@null@*/
376 rpmte rpmteSetParent(rpmte te, rpmte pte)
377         /*@modifies te @*/;
378
379 /**
380  * Retrieve number of children of transaction element.
381  * @param te            transaction element
382  * @return              tree index
383  */
384 int rpmteDegree(rpmte te)
385         /*@*/;
386
387 /**
388  * Set number of children of transaction element.
389  * @param te            transaction element
390  * @param ndegree       new number of children
391  * @return              previous number of children
392  */
393 int rpmteSetDegree(rpmte te, int ndegree)
394         /*@modifies te @*/;
395
396 /**
397  * Retrieve tsort info for transaction element.
398  * @param te            transaction element
399  * @return              tsort info
400  */
401 tsortInfo rpmteTSI(rpmte te)
402         /*@*/;
403
404 /**
405  * Destroy tsort info of transaction element.
406  * @param te            transaction element
407  */
408 void rpmteFreeTSI(rpmte te)
409         /*@modifies te @*/;
410
411 /**
412  * Initialize tsort info of transaction element.
413  * @param te            transaction element
414  */
415 void rpmteNewTSI(rpmte te)
416         /*@modifies te @*/;
417
418 /**
419  * Destroy dependency set info of transaction element.
420  * @param te            transaction element
421  */
422 /*@unused@*/
423 void rpmteCleanDS(rpmte te)
424         /*@modifies te @*/;
425
426 /**
427  * Retrieve pkgKey of TR_ADDED transaction element.
428  * @param te            transaction element
429  * @return              pkgKey
430  */
431 /*@exposed@*/ /*@dependent@*/ /*@null@*/
432 alKey rpmteAddedKey(rpmte te)
433         /*@*/;
434
435 /**
436  * Set pkgKey of TR_ADDED transaction element.
437  * @param te            transaction element
438  * @param npkgKey       new pkgKey
439  * @return              previous pkgKey
440  */
441 /*@exposed@*/ /*@dependent@*/ /*@null@*/
442 alKey rpmteSetAddedKey(rpmte te,
443                 /*@exposed@*/ /*@dependent@*/ /*@null@*/ alKey npkgKey)
444         /*@modifies te @*/;
445
446 /**
447  * Retrieve dependent pkgKey of TR_REMOVED transaction element.
448  * @param te            transaction element
449  * @return              dependent pkgKey
450  */
451 /*@exposed@*/ /*@dependent@*/ /*@null@*/
452 alKey rpmteDependsOnKey(rpmte te)
453         /*@*/;
454
455 /**
456  * Retrieve rpmdb instance of TR_REMOVED transaction element.
457  * @param te            transaction element
458  * @return              rpmdb instance
459  */
460 int rpmteDBOffset(rpmte te)
461         /*@*/;
462
463 /**
464  * Retrieve name-version-release string from transaction element.
465  * @param te            transaction element
466  * @return              name-version-release string
467  */
468 /*@observer@*/
469 extern const char * rpmteNEVR(rpmte te)
470         /*@*/;
471
472 /**
473  * Retrieve name-version-release.arch string from transaction element.
474  * @param te            transaction element
475  * @return              name-version-release.arch string
476  */
477 /*@-exportlocal@*/
478 /*@observer@*/
479 extern const char * rpmteNEVRA(rpmte te)
480         /*@*/;
481 /*@=exportlocal@*/
482
483 /**
484  * Retrieve file handle from transaction element.
485  * @param te            transaction element
486  * @return              file handle
487  */
488 FD_t rpmteFd(rpmte te)
489         /*@*/;
490
491 /**
492  * Retrieve key from transaction element.
493  * @param te            transaction element
494  * @return              key
495  */
496 /*@exposed@*/
497 fnpyKey rpmteKey(rpmte te)
498         /*@*/;
499
500 /**
501  * Retrieve dependency tag set from transaction element.
502  * @param te            transaction element
503  * @param tag           dependency tag
504  * @return              dependency tag set
505  */
506 rpmds rpmteDS(rpmte te, rpmTag tag)
507         /*@*/;
508
509 /**
510  * Retrieve file info tag set from transaction element.
511  * @param te            transaction element
512  * @param tag           file info tag (RPMTAG_BASENAMES)
513  * @return              file info tag set
514  */
515 rpmfi rpmteFI(rpmte te, rpmTag tag)
516         /*@*/;
517
518 /**
519  * Calculate transaction element dependency colors/refs from file info.
520  * @param te            transaction element
521  * @param tag           dependency tag (RPMTAG_PROVIDENAME, RPMTAG_REQUIRENAME)
522  */
523 /*@-exportlocal@*/
524 void rpmteColorDS(rpmte te, rpmTag tag)
525         /*@modifies te @*/;
526 /*@=exportlocal@*/
527
528 /**
529  * Return transaction element index.
530  * @param tsi           transaction element iterator
531  * @return              transaction element index
532  */
533 int rpmtsiOc(rpmtsi tsi)
534         /*@*/;
535
536 /**
537  * Destroy transaction element iterator.
538  * @param tsi           transaction element iterator
539  * @return              NULL always
540  */
541 /*@unused@*/ /*@null@*/
542 rpmtsi rpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi)
543         /*@globals fileSystem @*/
544         /*@modifies fileSystem @*/;
545
546 /**
547  * Destroy transaction element iterator.
548  * @param tsi           transaction element iterator
549  * @param fn
550  * @param ln
551  * @return              NULL always
552  */
553 /*@null@*/
554 rpmtsi XrpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi,
555                 const char * fn, unsigned int ln)
556         /*@globals fileSystem @*/
557         /*@modifies fileSystem @*/;
558 #define rpmtsiFree(_tsi)        XrpmtsiFree(_tsi, __FILE__, __LINE__)
559
560 /**
561  * Create transaction element iterator.
562  * @param ts            transaction set
563  * @return              transaction element iterator
564  */
565 /*@unused@*/ /*@only@*/
566 rpmtsi rpmtsiInit(rpmts ts)
567         /*@modifies ts @*/;
568
569 /**
570  * Create transaction element iterator.
571  * @param ts            transaction set
572  * @param fn
573  * @param ln
574  * @return              transaction element iterator
575  */
576 /*@unused@*/ /*@only@*/
577 rpmtsi XrpmtsiInit(rpmts ts,
578                 const char * fn, unsigned int ln)
579         /*@modifies ts @*/;
580 #define rpmtsiInit(_ts)         XrpmtsiInit(_ts, __FILE__, __LINE__)
581
582 /**
583  * Return next transaction element of type.
584  * @param tsi           transaction element iterator
585  * @param type          transaction element type selector (0 for any)
586  * @return              next transaction element of type, NULL on termination
587  */
588 /*@dependent@*/ /*@null@*/
589 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
590         /*@modifies tsi @*/;
591
592 #ifdef __cplusplus
593 }
594 #endif
595
596 #endif  /* H_RPMTE */