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