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