00001 #ifndef H_HEADER
00002 #define H_HEADER
00003
00080
00081
00082 #include <stdio.h>
00083 #include "rpmio.h"
00084
00085 #ifdef __cplusplus
00086 extern "C" {
00087 #endif
00088
00089 #if 0
00090 typedef long long int int_64;
00091 #endif
00092 typedef int int_32;
00093 typedef short int int_16;
00094 typedef char int_8;
00095
00096 #if 0
00097 typedef unsigned long long int uint_64;
00098 #endif
00099 typedef unsigned int uint_32;
00100 typedef unsigned short uint_16;
00101 typedef unsigned char uint_8;
00102
00103
00106 typedef const char * errmsg_t;
00107
00110 typedef int_32 * hTAG_t;
00111 typedef int_32 * hTYP_t;
00112 typedef const void * hPTR_t;
00113 typedef int_32 * hCNT_t;
00114
00117 typedef struct headerToken_s * Header;
00118
00121 typedef struct headerIterator_s * HeaderIterator;
00122
00126 typedef struct headerTagTableEntry_s * headerTagTableEntry;
00127 struct headerTagTableEntry_s {
00128
00129 const char * name;
00130 int val;
00131 };
00132
00135 enum headerSprintfExtensionType {
00136 HEADER_EXT_LAST = 0,
00137 HEADER_EXT_FORMAT,
00138 HEADER_EXT_MORE,
00139 HEADER_EXT_TAG
00140 };
00141
00154 typedef char * (*headerTagFormatFunction)(int_32 type,
00155 const void * data, char * formatPrefix,
00156 int padding, int element)
00157 ;
00158
00170 typedef int (*headerTagTagFunction) (Header h,
00171 hTYP_t type,
00172 hPTR_t * data,
00173 hCNT_t count,
00174 int * freeData)
00175
00176 ;
00177
00181 typedef struct headerSprintfExtension_s * headerSprintfExtension;
00182 struct headerSprintfExtension_s {
00183 enum headerSprintfExtensionType type;
00184
00185 const char * name;
00186 union {
00187
00188 void * generic;
00189 headerTagFormatFunction formatFunction;
00190 headerTagTagFunction tagFunction;
00191 struct headerSprintfExtension_s * more;
00192 } u;
00193 };
00194
00198
00199
00200 extern const struct headerSprintfExtension_s headerDefaultFormats[];
00201
00202
00206 enum hMagic {
00207 HEADER_MAGIC_NO = 0,
00208 HEADER_MAGIC_YES = 1
00209 };
00210
00214 typedef enum rpmTagType_e {
00215 #define RPM_MIN_TYPE 0
00216 RPM_NULL_TYPE = 0,
00217 RPM_CHAR_TYPE = 1,
00218 RPM_INT8_TYPE = 2,
00219 RPM_INT16_TYPE = 3,
00220 RPM_INT32_TYPE = 4,
00221
00222 RPM_STRING_TYPE = 6,
00223 RPM_BIN_TYPE = 7,
00224 RPM_STRING_ARRAY_TYPE = 8,
00225 RPM_I18NSTRING_TYPE = 9
00226 #define RPM_MAX_TYPE 9
00227 } rpmTagType;
00228
00237
00238 typedef enum rpmSubTagType_e {
00239 RPM_REGION_TYPE = -10,
00240 RPM_BIN_ARRAY_TYPE = -11,
00243 RPM_XREF_TYPE = -12
00246 } rpmSubTagType;
00247
00248
00253 #define HEADER_IMAGE 61
00254 #define HEADER_SIGNATURES 62
00255 #define HEADER_IMMUTABLE 63
00256 #define HEADER_REGIONS 64
00257 #define HEADER_I18NTABLE 100
00258 #define HEADER_SIGBASE 256
00259 #define HEADER_TAGBASE 1000
00260
00263
00264 typedef union hRET_s {
00265 const void * ptr;
00266 const char ** argv;
00267 const char * str;
00268 uint_32 * ui32p;
00269 uint_16 * ui16p;
00270 int_32 * i32p;
00271 int_16 * i16p;
00272 int_8 * i8p;
00273 } * hRET_t;
00274
00275
00278
00279 typedef struct HE_s {
00280 int_32 tag;
00281
00282 hTYP_t typ;
00283 union {
00284
00285 hPTR_t * ptr;
00286
00287 hRET_t * ret;
00288 } u;
00289
00290 hCNT_t cnt;
00291 } * HE_t;
00292
00293
00298 typedef
00299 Header (*HDRnew) (void)
00300 ;
00301
00307 typedef
00308 Header (*HDRfree) ( Header h)
00309 ;
00310
00316 typedef
00317 Header (*HDRlink) (Header h)
00318 ;
00319
00325 typedef
00326 Header (*HDRunlink) ( Header h)
00327 ;
00328
00334 typedef
00335 void (*HDRsort) (Header h)
00336 ;
00337
00343 typedef
00344 void (*HDRunsort) (Header h)
00345 ;
00346
00353 typedef
00354 unsigned int (*HDRsizeof) ( Header h, enum hMagic magicp)
00355 ;
00356
00362 typedef
00363 void * (*HDRunload) (Header h)
00364 ;
00365
00373 typedef
00374 Header (*HDRreload) ( Header h, int tag)
00375 ;
00376
00382 typedef
00383 Header (*HDRcopy) (Header h)
00384 ;
00385
00391 typedef
00392 Header (*HDRload) ( void * uh)
00393 ;
00394
00400 typedef
00401 Header (*HDRcopyload) (const void * uh)
00402 ;
00403
00410 typedef
00411 Header (*HDRread) (FD_t fd, enum hMagic magicp)
00412 ;
00413
00421 typedef
00422 int (*HDRwrite) (FD_t fd, Header h, enum hMagic magicp)
00423
00424 ;
00425
00432 typedef
00433 int (*HDRisentry) (Header h, int_32 tag)
00434 ;
00435
00443 typedef
00444 void * (*HDRfreetag) (Header h,
00445 const void * data, rpmTagType type)
00446 ;
00447
00461 typedef
00462 int (*HDRget) (Header h, int_32 tag,
00463 hTYP_t type,
00464 void ** p,
00465 hCNT_t c)
00466 ;
00467
00480 typedef
00481 int (*HDRgetmin) (Header h, int_32 tag,
00482 hTYP_t type,
00483 hPTR_t * p,
00484 hCNT_t c)
00485 ;
00486
00501 typedef
00502 int (*HDRadd) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00503 ;
00504
00519 typedef
00520 int (*HDRappend) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00521 ;
00522
00533 typedef
00534 int (*HDRaddorappend) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00535 ;
00536
00557 typedef
00558 int (*HDRaddi18n) (Header h, int_32 tag, const char * string,
00559 const char * lang)
00560 ;
00561
00572 typedef
00573 int (*HDRmodify) (Header h, int_32 tag, int_32 type, const void * p, int_32 c)
00574 ;
00575
00585 typedef
00586 int (*HDRremove) (Header h, int_32 tag)
00587 ;
00588
00600 typedef
00601 char * (*HDRsprintf) (Header h, const char * fmt,
00602 const struct headerTagTableEntry_s * tags,
00603 const struct headerSprintfExtension_s * extensions,
00604 errmsg_t * errmsg)
00605 ;
00606
00613 typedef
00614 void (*HDRcopytags) (Header headerFrom, Header headerTo, hTAG_t tagstocopy)
00615 ;
00616
00622 typedef
00623 HeaderIterator (*HDRfreeiter) ( HeaderIterator hi)
00624 ;
00625
00631 typedef
00632 HeaderIterator (*HDRinititer) (Header h)
00633 ;
00634
00644 typedef
00645 int (*HDRnextiter) (HeaderIterator hi,
00646 hTAG_t tag,
00647 hTYP_t type,
00648 hPTR_t * p,
00649 hCNT_t c)
00650 ;
00651
00655 typedef struct HV_s * HV_t;
00656 struct HV_s {
00657 HDRlink hdrlink;
00658 HDRunlink hdrunlink;
00659 HDRfree hdrfree;
00660 HDRnew hdrnew;
00661 HDRsort hdrsort;
00662 HDRunsort hdrunsort;
00663 HDRsizeof hdrsizeof;
00664 HDRunload hdrunload;
00665 HDRreload hdrreload;
00666 HDRcopy hdrcopy;
00667 HDRload hdrload;
00668 HDRcopyload hdrcopyload;
00669 HDRread hdrread;
00670 HDRwrite hdrwrite;
00671 HDRisentry hdrisentry;
00672 HDRfreetag hdrfreetag;
00673 HDRget hdrget;
00674 HDRgetmin hdrgetmin;
00675 HDRadd hdradd;
00676 HDRappend hdrappend;
00677 HDRaddorappend hdraddorappend;
00678 HDRaddi18n hdraddi18n;
00679 HDRmodify hdrmodify;
00680 HDRremove hdrremove;
00681 HDRsprintf hdrsprintf;
00682 HDRcopytags hdrcopytags;
00683 HDRfreeiter hdrfreeiter;
00684 HDRinititer hdrinititer;
00685 HDRnextiter hdrnextiter;
00686
00687 void * hdrvecs;
00688
00689 void * hdrdata;
00690 int hdrversion;
00691 };
00692
00702 static inline
00703 void * headerFreeData( const void * data, rpmTagType type)
00704
00705 {
00706 if (data) {
00707
00708 if (type == -1 ||
00709 type == RPM_STRING_ARRAY_TYPE ||
00710 type == RPM_I18NSTRING_TYPE ||
00711 type == RPM_BIN_TYPE)
00712 free((void *)data);
00713
00714 }
00715 return NULL;
00716 }
00717
00718 #if !defined(__HEADER_PROTOTYPES__)
00719 #include "hdrinline.h"
00720 #endif
00721
00722 #ifdef __cplusplus
00723 }
00724 #endif
00725
00726 #endif