# lib/header.h

Go to the documentation of this file.

    00001 #ifndef H_HEADER
    00002 #define H_HEADER
    00003
    00078 /* RPM - Copyright (C) 1995-2001 Red Hat Software */
    00079
    00080 #include <stdio.h>
    00081 #include <rpmio.h>
    00082
    00083 #ifdef __cplusplus
    00084 extern "C" {
    00085 #endif
    00086
    00087 #if defined(__alpha__) || defined(__alpha)
    00088 typedef long int int_64;
    00089 typedef int int_32;
    00090 typedef short int int_16;
    00091 typedef char int_8;
    00092
    00093 typedef unsigned int uint_32;
    00094 typedef unsigned short uint_16;
    00095
    00096 #else
    00097
    00098 #if 0   /* XXX hpux needs -Ae in CFLAGS to grok this */
    00099 typedef long long int int_64;
    00100 #endif
    00101 typedef int int_32;
    00102 typedef short int int_16;
    00103 typedef char int_8;
    00104
    00105 typedef unsigned int uint_32;
    00106 typedef unsigned short uint_16;
    00107 #endif
    00108
    00109 /*@-redef@*/    /* LCL: no clue */
    00112 typedef const char *    errmsg_t;
    00113
    00116 typedef int_32 *        hTAG_t;
    00117 typedef int_32 *        hTYP_t;
    00118 typedef const void *    hPTR_t;
    00119 typedef int_32 *        hCNT_t;
    00120
    00123 typedef /*@abstract@*/ /*@refcounted@*/ struct headerToken * Header;
    00124
    00127 typedef /*@abstract@*/ struct headerIteratorS * HeaderIterator;
    00128
    00132 typedef /*@abstract@*/ struct headerTagTableEntry_s * headerTagTableEntry;
    00133 struct headerTagTableEntry_s {
    00134 /*@observer@*/ /*@null@*/ const char * name;
    00135     int val;
    00136 };
    00137
    00140 enum headerSprintfExtenstionType {
    00141     HEADER_EXT_LAST = 0,
    00142     HEADER_EXT_FORMAT,
    00143     HEADER_EXT_MORE,
    00144     HEADER_EXT_TAG
    00145 };
    00146
    00159 typedef /*only@*/ char * (*headerTagFormatFunction)(int_32 type,
    00160                                 const void * data, char * formatPrefix,
    00161                                 int padding, int element);
    00173 typedef int (*headerTagTagFunction) (Header h,
    00174                 /*@null@*/ /*@out@*/ hTYP_t type,
    00175                 /*@null@*/ /*@out@*/ hPTR_t * data,
    00176                 /*@null@*/ /*@out@*/ hCNT_t count,
    00177                 /*@null@*/ /*@out@*/ int * freeData);
    00178
    00182 typedef /*@abstract@*/ struct headerSprintfExtension_s * headerSprintfExtension;
    00183 struct headerSprintfExtension_s {
    00184     enum headerSprintfExtenstionType type;
    00185 /*@observer@*/ /*@null@*/
    00186     const char * name;
    00187     union {
    00188 /*@observer@*/ /*@null@*/
    00189         void * generic;
    00190         headerTagFormatFunction formatFunction;
    00191         headerTagTagFunction tagFunction;
    00192         struct headerSprintfExtension_s * more;
    00193     } u;
    00194 };
    00195
    00199 /*@-redecl@*/
    00200 /*@observer@*/
    00201 extern const struct headerSprintfExtension_s headerDefaultFormats[];
    00202 /*@=redecl@*/
    00203
    00207 enum hMagic {
    00208         HEADER_MAGIC_NO         = 0,
    00209         HEADER_MAGIC_YES        = 1
    00210 };
    00211
    00215 typedef enum rpmTagType_e {
    00216 #define RPM_MIN_TYPE            0
    00217     RPM_NULL_TYPE               =  0,
    00218     RPM_CHAR_TYPE               =  1,
    00219     RPM_INT8_TYPE               =  2,
    00220     RPM_INT16_TYPE              =  3,
    00221     RPM_INT32_TYPE              =  4,
    00222 /*    RPM_INT64_TYPE    = 5,   ---- These aren't supported (yet) */
    00223     RPM_STRING_TYPE             =  6,
    00224     RPM_BIN_TYPE                =  7,
    00225     RPM_STRING_ARRAY_TYPE       =  8,
    00226     RPM_I18NSTRING_TYPE         =  9
    00227 #define RPM_MAX_TYPE            9
    00228 } rpmTagType;
    00229
    00238 /*@-enummemuse -typeuse @*/
    00239 typedef enum rpmSubTagType_e {
    00240         RPM_REGION_TYPE         = -10,
    00241         RPM_BIN_ARRAY_TYPE      = -11,
    00244         RPM_XREF_TYPE           = -12
    00247 } rpmSubTagType;
    00248 /*@=enummemuse =typeuse @*/
    00249
    00254 #define HEADER_IMAGE            61
    00255 #define HEADER_SIGNATURES       62
    00256 #define HEADER_IMMUTABLE        63
    00257 #define HEADER_REGIONS          64
    00258 #define HEADER_I18NTABLE        100
    00259 #define HEADER_SIGBASE          256
    00260 #define HEADER_TAGBASE          1000
    00261
    00264 /*@-typeuse -fielduse@*/
    00265 typedef union hRET_s {
    00266     const void * ptr;
    00267     const char ** argv;
    00268     const char * str;
    00269     uint_32 * ui32p;
    00270     uint_16 * ui16p;
    00271     int_32 * i32p;
    00272     int_16 * i16p;
    00273     int_8 * i8p;
    00274 } * hRET_t;
    00275 /*@=typeuse =fielduse@*/
    00276
    00279 /*@-typeuse -fielduse@*/
    00280 typedef struct HE_s {
    00281     int_32 tag;
    00282 /*@null@*/ hTYP_t typ;
    00283     union {
    00284 /*@null@*/ hPTR_t * ptr;
    00285 /*@null@*/ hRET_t * ret;
    00286     } u;
    00287 /*@null@*/ hCNT_t cnt;
    00288 } * HE_t;
    00289 /*@=typeuse =fielduse@*/
    00290
    00295 typedef
    00296 Header (*HDRnew) (void)
    00297         /*@*/;
    00298
    00304 typedef
    00305 /*@null@*/ Header (*HDRfree) (/*@null@*/ /*@killref@*/ Header h)
    00306         /*@modifies h @*/;
    00307
    00313 typedef
    00314 Header (*HDRlink) (Header h)
    00315         /*@modifies h @*/;
    00316
    00322 typedef
    00323 Header (*HDRunlink) (/*@killref@*/ /*@null@*/ Header h)
    00324          /*@modifies h @*/;
    00325
    00331 typedef
    00332 void (*HDRsort) (Header h)
    00333         /*@modifies h @*/;
    00334
    00340 typedef
    00341 void (*HDRunsort) (Header h)
    00342         /*@modifies h @*/;
    00343
    00350 typedef
    00351 unsigned int (*HDRsizeof) (/*@null@*/ Header h, enum hMagic magicp)
    00352         /*@modifies h @*/;
    00353
    00359 typedef
    00360 /*@only@*/ /*@null@*/ void * (*HDRunload) (Header h)
    00361         /*@modifies h @*/;
    00362
    00370 typedef
    00371 /*@null@*/ Header (*HDRreload) (/*@only@*/ Header h, int tag)
    00372         /*@modifies h @*/;
    00373
    00379 typedef
    00380 Header (*HDRcopy) (Header h)
    00381         /*@modifies h @*/;
    00382
    00388 typedef
    00389 /*@null@*/ Header (*HDRload) (/*@kept@*/ void * uh)
    00390         /*@modifies uh @*/;
    00391
    00397 typedef
    00398 /*@null@*/ Header (*HDRcopyload) (const void * uh)
    00399         /*@*/;
    00400
    00407 typedef
    00408 /*@null@*/ Header (*HDRhdrread) (FD_t fd, enum hMagic magicp)
    00409         /*@modifies fd @*/;
    00410
    00418 typedef
    00419 int (*HDRhdrwrite) (FD_t fd, /*@null@*/ Header h, enum hMagic magicp)
    00420         /*@globals fileSystem @*/
    00421         /*@modifies fd, h, fileSystem @*/;
    00422
    00429 typedef
    00430 int (*HDRisentry) (/*@null@*/Header h, int_32 tag)
    00431         /*@*/;
    00432
    00440 typedef
    00441 /*@null@*/ void * (*HDRfreetag) (Header h,
    00442                 /*@only@*/ /*@null@*/ const void * data, rpmTagType type)
    00443         /*@modifies data @*/;
    00444
    00458 typedef
    00459 int (*HDRget) (Header h, int_32 tag,
    00460                         /*@null@*/ /*@out@*/ hTYP_t type,
    00461                         /*@null@*/ /*@out@*/ void ** p,
    00462                         /*@null@*/ /*@out@*/ hCNT_t c)
    00463         /*@modifies *type, *p, *c @*/;
    00464
    00477 typedef
    00478 int (*HDRgetmin) (Header h, int_32 tag,
    00479                         /*@null@*/ /*@out@*/ hTYP_t type,
    00480                         /*@null@*/ /*@out@*/ hPTR_t * p,
    00481                         /*@null@*/ /*@out@*/ hCNT_t c)
    00482         /*@modifies *type, *p, *c @*/;
    00483
    00498 typedef
    00499 int (*HDRadd) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
    00500         /*@modifies h @*/;
    00501
    00516 typedef
    00517 int (*HDRappend) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
    00518         /*@modifies h @*/;
    00519
    00530 typedef
    00531 int (*HDRaddorappend) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
    00532         /*@modifies h @*/;
    00533
    00554 typedef
    00555 int (*HDRaddi18n) (Header h, int_32 tag, const char * string,
    00556                 const char * lang)
    00557         /*@modifies h @*/;
    00558
    00569 typedef
    00570 int (*HDRmodify) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
    00571         /*@modifies h @*/;
    00572
    00582 typedef
    00583 int (*HDRremove) (Header h, int_32 tag)
    00584         /*@modifies h @*/;
    00585
    00597 typedef
    00598 /*@only@*/ char * (*HDRhdrsprintf) (Header h, const char * fmt,
    00599                      const struct headerTagTableEntry_s * tags,
    00600                      const struct headerSprintfExtension_s * extensions,
    00601                      /*@null@*/ /*@out@*/ errmsg_t * errmsg)
    00602         /*@modifies *errmsg @*/;
    00603
    00610 typedef
    00611 void (*HDRcopytags) (Header headerFrom, Header headerTo, hTAG_t tagstocopy)
    00612         /*@modifies headerFrom, headerTo @*/;
    00613
    00619 typedef
    00620 HeaderIterator (*HDRfreeiter) (/*@only@*/ HeaderIterator hi)
    00621         /*@modifies hi @*/;
    00622
    00628 typedef
    00629 HeaderIterator (*HDRinititer) (Header h)
    00630         /*@modifies h */;
    00631
    00641 typedef
    00642 int (*HDRnextiter) (HeaderIterator hi,
    00643                 /*@null@*/ /*@out@*/ hTAG_t tag,
    00644                 /*@null@*/ /*@out@*/ hTYP_t type,
    00645                 /*@null@*/ /*@out@*/ hPTR_t * p,
    00646                 /*@null@*/ /*@out@*/ hCNT_t c)
    00647         /*@modifies hi, *tag, *type, *p, *c @*/;
    00648
    00652 typedef /*@abstract@*/ struct HV_s * HV_t;
    00653 struct HV_s {
    00654     HDRnew      hdrnew;
    00655     HDRfree     hdrfree;
    00656     HDRlink     hdrlink;
    00657     HDRsort     hdrsort;
    00658     HDRunsort   hdrunsort;
    00659     HDRsizeof   hdrsizeof;
    00660     HDRunload   hdrunload;
    00661     HDRreload   hdrreload;
    00662     HDRcopy     hdrcopy;
    00663     HDRload     hdrload;
    00664     HDRcopyload hdrcopyload;
    00665     HDRhdrread  hdrread;
    00666     HDRhdrwrite hdrwrite;
    00667     HDRisentry  hdrisentry;
    00668     HDRfreetag  hdrfreetag;
    00669     HDRget      hdrget;
    00670     HDRgetmin   hdrgetmin;
    00671     HDRadd      hdradd;
    00672     HDRappend   hdrappend;
    00673     HDRaddorappend hdraddorappend;
    00674     HDRaddi18n  hdraddi18n;
    00675     HDRmodify   hdrmodify;
    00676     HDRremove   hdrremove;
    00677     HDRhdrsprintf hdrsprintf;
    00678     HDRcopytags hdrcopytags;
    00679     HDRfreeiter hdrfreeiter;
    00680     HDRinititer hdrinititer;
    00681     HDRnextiter hdrnextiter;
    00682     HDRunlink   hdrunlink;
    00683 /*@null@*/
    00684     void *      hdrvecs;
    00685 /*@null@*/
    00686     void *      hdrdata;
    00687     int         hdrversion;
    00688 };
    00689
    00699 /*@unused@*/ static inline /*@null@*/
    00700 void * headerFreeData( /*@only@*/ /*@null@*/ const void * data, rpmTagType type)
    00701         /*@modifies data @*/
    00702 {
    00703     if (data) {
    00704         /*@-branchstate@*/
    00705         if (type == -1 ||
    00706             type == RPM_STRING_ARRAY_TYPE ||
    00707             type == RPM_I18NSTRING_TYPE ||
    00708             type == RPM_BIN_TYPE)
    00709                 free((void *)data);
    00710         /*@=branchstate@*/
    00711     }
    00712     return NULL;
    00713 }
    00714
    00715 #if !defined(__HEADER_PROTOTYPES__)
    00716 #include <hdrinline.h>
    00717 #endif
    00718
    00719 #ifdef __cplusplus
    00720 }
    00721 #endif
    00722
    00723 #endif  /* H_HEADER */