00001 #ifndef H_HEADER
00002 #define H_HEADER
00003
00078
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
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
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 struct headerToken * Header;
00124
00127 typedef struct headerIteratorS * HeaderIterator;
00128
00132 typedef struct headerTagTableEntry_s * headerTagTableEntry;
00133 struct headerTagTableEntry_s {
00134 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 char * (*headerTagFormatFunction)(int_32 type,
00160 const void * data, char * formatPrefix,
00161 int padding, int element);
00173 typedef int (*headerTagTagFunction) (Header h,
00174 hTYP_t type,
00175 hPTR_t * data,
00176 hCNT_t count,
00177 int * freeData);
00178
00182 typedef struct headerSprintfExtension_s * headerSprintfExtension;
00183 struct headerSprintfExtension_s {
00184 enum headerSprintfExtenstionType type;
00185
00186 const char * name;
00187 union {
00188
00189 void * generic;
00190 headerTagFormatFunction formatFunction;
00191 headerTagTagFunction tagFunction;
00192 struct headerSprintfExtension_s * more;
00193 } u;
00194 };
00195
00199
00200
00201 extern const struct headerSprintfExtension_s headerDefaultFormats[];
00202
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
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
00239 typedef enum rpmSubTagType_e {
00240 RPM_REGION_TYPE = -10,
00241 RPM_BIN_ARRAY_TYPE = -11,
00244 RPM_XREF_TYPE = -12
00247 } rpmSubTagType;
00248
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
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
00276
00279
00280 typedef struct HE_s {
00281 int_32 tag;
00282 hTYP_t typ;
00283 union {
00284 hPTR_t * ptr;
00285 hRET_t * ret;
00286 } u;
00287 hCNT_t cnt;
00288 } * HE_t;
00289
00290
00295 typedef
00296 Header (*HDRnew) (void)
00297 ;
00298
00304 typedef
00305 Header (*HDRfree) ( Header h)
00306 ;
00307
00313 typedef
00314 Header (*HDRlink) (Header h)
00315 ;
00316
00322 typedef
00323 Header (*HDRunlink) ( Header h)
00324 ;
00325
00331 typedef
00332 void (*HDRsort) (Header h)
00333 ;
00334
00340 typedef
00341 void (*HDRunsort) (Header h)
00342 ;
00343
00350 typedef
00351 unsigned int (*HDRsizeof) ( Header h, enum hMagic magicp)
00352 ;
00353
00359 typedef
00360 void * (*HDRunload) (Header h)
00361 ;
00362
00370 typedef
00371 Header (*HDRreload) ( Header h, int tag)
00372 ;
00373
00379 typedef
00380 Header (*HDRcopy) (Header h)
00381 ;
00382
00388 typedef
00389 Header (*HDRload) ( void * uh)
00390 ;
00391
00397 typedef
00398 Header (*HDRcopyload) (const void * uh)
00399 ;
00400
00407 typedef
00408 Header (*HDRhdrread) (FD_t fd, enum hMagic magicp)
00409 ;
00410
00418 typedef
00419 int (*HDRhdrwrite) (FD_t fd, Header h, enum hMagic magicp)
00420
00421 ;
00422
00429 typedef
00430 int (*HDRisentry) (Header h, int_32 tag)
00431 ;
00432
00440 typedef
00441 void * (*HDRfreetag) (Header h,
00442 const void * data, rpmTagType type)
00443 ;
00444
00458 typedef
00459 int (*HDRget) (Header h, int_32 tag,
00460 hTYP_t type,
00461 void ** p,
00462 hCNT_t c)
00463 ;
00464
00477 typedef
00478 int (*HDRgetmin) (Header h, int_32 tag,
00479 hTYP_t type,
00480 hPTR_t * p,
00481 hCNT_t c)
00482 ;
00483
00498 typedef
00499 int (*HDRadd) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00500 ;
00501
00516 typedef
00517 int (*HDRappend) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00518 ;
00519
00530 typedef
00531 int (*HDRaddorappend) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00532 ;
00533
00554 typedef
00555 int (*HDRaddi18n) (Header h, int_32 tag, const char * string,
00556 const char * lang)
00557 ;
00558
00569 typedef
00570 int (*HDRmodify) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00571 ;
00572
00582 typedef
00583 int (*HDRremove) (Header h, int_32 tag)
00584 ;
00585
00597 typedef
00598 char * (*HDRhdrsprintf) (Header h, const char * fmt,
00599 const struct headerTagTableEntry_s * tags,
00600 const struct headerSprintfExtension_s * extensions,
00601 errmsg_t * errmsg)
00602 ;
00603
00610 typedef
00611 void (*HDRcopytags) (Header headerFrom, Header headerTo, hTAG_t tagstocopy)
00612 ;
00613
00619 typedef
00620 HeaderIterator (*HDRfreeiter) ( HeaderIterator hi)
00621 ;
00622
00628 typedef
00629 HeaderIterator (*HDRinititer) (Header h)
00630 ;
00631
00641 typedef
00642 int (*HDRnextiter) (HeaderIterator hi,
00643 hTAG_t tag,
00644 hTYP_t type,
00645 hPTR_t * p,
00646 hCNT_t c)
00647 ;
00648
00652 typedef 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
00684 void * hdrvecs;
00685
00686 void * hdrdata;
00687 int hdrversion;
00688 };
00689
00699 static inline
00700 void * headerFreeData( const void * data, rpmTagType type)
00701
00702 {
00703 if (data) {
00704
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
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