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 const char * name;
00186 union {
00187 void * generic;
00188 headerTagFormatFunction formatFunction;
00189 headerTagTagFunction tagFunction;
00190 struct headerSprintfExtension_s * more;
00191 } u;
00192 };
00193
00197
00198 extern const struct headerSprintfExtension_s headerDefaultFormats[];
00199
00200
00204 enum hMagic {
00205 HEADER_MAGIC_NO = 0,
00206 HEADER_MAGIC_YES = 1
00207 };
00208
00212 typedef enum rpmTagType_e {
00213 #define RPM_MIN_TYPE 0
00214 RPM_NULL_TYPE = 0,
00215 RPM_CHAR_TYPE = 1,
00216 RPM_INT8_TYPE = 2,
00217 RPM_INT16_TYPE = 3,
00218 RPM_INT32_TYPE = 4,
00219
00220 RPM_STRING_TYPE = 6,
00221 RPM_BIN_TYPE = 7,
00222 RPM_STRING_ARRAY_TYPE = 8,
00223 RPM_I18NSTRING_TYPE = 9
00224 #define RPM_MAX_TYPE 9
00225 } rpmTagType;
00226
00235
00236 typedef enum rpmSubTagType_e {
00237 RPM_REGION_TYPE = -10,
00238 RPM_BIN_ARRAY_TYPE = -11,
00241 RPM_XREF_TYPE = -12
00244 } rpmSubTagType;
00245
00246
00251 #define HEADER_IMAGE 61
00252 #define HEADER_SIGNATURES 62
00253 #define HEADER_IMMUTABLE 63
00254 #define HEADER_REGIONS 64
00255 #define HEADER_I18NTABLE 100
00256 #define HEADER_SIGBASE 256
00257 #define HEADER_TAGBASE 1000
00258
00261
00262 typedef union hRET_s {
00263 const void * ptr;
00264 const char ** argv;
00265 const char * str;
00266 uint_32 * ui32p;
00267 uint_16 * ui16p;
00268 int_32 * i32p;
00269 int_16 * i16p;
00270 int_8 * i8p;
00271 } * hRET_t;
00272
00273
00276
00277 typedef struct HE_s {
00278 int_32 tag;
00279 hTYP_t typ;
00280 union {
00281 hPTR_t * ptr;
00282 hRET_t * ret;
00283 } u;
00284 hCNT_t cnt;
00285 } * HE_t;
00286
00287
00292 typedef
00293 Header (*HDRnew) (void)
00294 ;
00295
00301 typedef
00302 Header (*HDRfree) ( Header h)
00303 ;
00304
00310 typedef
00311 Header (*HDRlink) (Header h)
00312 ;
00313
00319 typedef
00320 void (*HDRsort) (Header h)
00321 ;
00322
00328 typedef
00329 void (*HDRunsort) (Header h)
00330 ;
00331
00338 typedef
00339 unsigned int (*HDRsizeof) ( Header h, enum hMagic magicp)
00340 ;
00341
00347 typedef
00348 void * (*HDRunload) (Header h)
00349 ;
00350
00358 typedef
00359 Header (*HDRreload) ( Header h, int tag)
00360 ;
00361
00367 typedef
00368 Header (*HDRcopy) (Header h)
00369 ;
00370
00376 typedef
00377 Header (*HDRload) ( void * uh)
00378 ;
00379
00385 typedef
00386 Header (*HDRcopyload) (const void * uh)
00387 ;
00388
00395 typedef
00396 Header (*HDRhdrread) (FD_t fd, enum hMagic magicp)
00397 ;
00398
00406 typedef
00407 int (*HDRhdrwrite) (FD_t fd, Header h, enum hMagic magicp)
00408 ;
00409
00416 typedef
00417 int (*HDRisentry) (Header h, int_32 tag)
00418 ;
00419
00427 typedef
00428 void * (*HDRfreetag) (Header h,
00429 const void * data, rpmTagType type)
00430 ;
00431
00445 typedef
00446 int (*HDRget) (Header h, int_32 tag,
00447 hTYP_t type,
00448 void ** p,
00449 hCNT_t c)
00450 ;
00451
00464 typedef
00465 int (*HDRgetmin) (Header h, int_32 tag,
00466 hTYP_t type,
00467 hPTR_t * p,
00468 hCNT_t c)
00469 ;
00470
00485 typedef
00486 int (*HDRadd) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00487 ;
00488
00503 typedef
00504 int (*HDRappend) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00505 ;
00506
00517 typedef
00518 int (*HDRaddorappend) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00519 ;
00520
00541 typedef
00542 int (*HDRaddi18n) (Header h, int_32 tag, const char * string,
00543 const char * lang)
00544 ;
00545
00556 typedef
00557 int (*HDRmodify) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00558 ;
00559
00569 typedef
00570 int (*HDRremove) (Header h, int_32 tag)
00571 ;
00572
00584 typedef
00585 char * (*HDRhdrsprintf) (Header h, const char * fmt,
00586 const struct headerTagTableEntry_s * tags,
00587 const struct headerSprintfExtension_s * extensions,
00588 errmsg_t * errmsg)
00589 ;
00590
00597 typedef
00598 void (*HDRcopytags) (Header headerFrom, Header headerTo, hTAG_t tagstocopy)
00599 ;
00600
00606 typedef
00607 HeaderIterator (*HDRfreeiter) ( HeaderIterator hi)
00608 ;
00609
00615 typedef
00616 HeaderIterator (*HDRinititer) (Header h)
00617 ;
00618
00628 typedef
00629 int (*HDRnextiter) (HeaderIterator hi,
00630 hTAG_t tag,
00631 hTYP_t type,
00632 hPTR_t * p,
00633 hCNT_t c)
00634 ;
00635
00639 typedef struct HV_s * HV_t;
00640 struct HV_s {
00641 HDRnew hdrnew;
00642 HDRfree hdrfree;
00643 HDRlink hdrlink;
00644 HDRsort hdrsort;
00645 HDRunsort hdrunsort;
00646 HDRsizeof hdrsizeof;
00647 HDRunload hdrunload;
00648 HDRreload hdrreload;
00649 HDRcopy hdrcopy;
00650 HDRload hdrload;
00651 HDRcopyload hdrcopyload;
00652 HDRhdrread hdrread;
00653 HDRhdrwrite hdrwrite;
00654 HDRisentry hdrisentry;
00655 HDRfreetag hdrfreetag;
00656 HDRget hdrget;
00657 HDRgetmin hdrgetmin;
00658 HDRadd hdradd;
00659 HDRappend hdrappend;
00660 HDRaddorappend hdraddorappend;
00661 HDRaddi18n hdraddi18n;
00662 HDRmodify hdrmodify;
00663 HDRremove hdrremove;
00664 HDRhdrsprintf hdrsprintf;
00665 HDRcopytags hdrcopytags;
00666 HDRfreeiter hdrfreeiter;
00667 HDRinititer hdrinititer;
00668 HDRnextiter hdrnextiter;
00669 void * hdrvecs;
00670 void * hdrdata;
00671 int hdrversion;
00672 };
00673
00683 static inline
00684 void * headerFreeData( const void * data, rpmTagType type)
00685
00686 {
00687 if (data) {
00688
00689 if (type == -1 ||
00690 type == RPM_STRING_ARRAY_TYPE ||
00691 type == RPM_I18NSTRING_TYPE ||
00692 type == RPM_BIN_TYPE)
00693 free((void *)data);
00694
00695 }
00696 return NULL;
00697 }
00698
00699 #if defined(__HEADER_PROTOTYPES__)
00700 #include <hdrproto.h>
00701 #else
00702 #include <hdrinline.h>
00703 #endif
00704
00705 #ifdef __cplusplus
00706 }
00707 #endif
00708
00709 #endif