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