00001 #ifndef H_HEADER
00002 #define H_HEADER
00003
00064
00065
00066
00067
00068 #include <stdio.h>
00069 #include <rpmio.h>
00070
00071 #ifdef __cplusplus
00072 extern "C" {
00073 #endif
00074
00075 #if defined(__alpha__) || defined(__alpha)
00076 typedef long int int_64;
00077 typedef int int_32;
00078 typedef short int int_16;
00079 typedef char int_8;
00080
00081 typedef unsigned int uint_32;
00082 typedef unsigned short uint_16;
00083
00084 #else
00085
00086 #if 0
00087 typedef long long int int_64;
00088 #endif
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 #endif
00096
00099 typedef struct headerToken *Header;
00100
00103 typedef struct headerIteratorS *HeaderIterator;
00104
00108 struct headerTagTableEntry {
00109 const char * name;
00110 int val;
00111 };
00112
00115 enum headerSprintfExtenstionType {
00116 HEADER_EXT_LAST = 0,
00117 HEADER_EXT_FORMAT,
00118 HEADER_EXT_MORE,
00119 HEADER_EXT_TAG
00120 };
00121
00134 typedef char * (*headerTagFormatFunction)(int_32 type,
00135 const void * data, char * formatPrefix,
00136 int padding, int element);
00148 typedef int (*headerTagTagFunction)(Header h, int_32 * type, const void ** data,
00149 int_32 * count, int * freeData);
00150
00154 struct headerSprintfExtension {
00155 enum headerSprintfExtenstionType type;
00156 char * name;
00157 union {
00158 void * generic;
00159 headerTagFormatFunction formatFunction;
00160 headerTagTagFunction tagFunction;
00161 struct headerSprintfExtension * more;
00162 } u;
00163 };
00164
00168 extern const struct headerSprintfExtension headerDefaultFormats[];
00169
00173 enum hMagic {
00174 HEADER_MAGIC_NO = 0,
00175 HEADER_MAGIC_YES = 1
00176 };
00177
00184 Header headerRead(FD_t fd, enum hMagic magicp)
00185 ;
00186
00194 int headerWrite(FD_t fd, Header h, enum hMagic magicp)
00195 ;
00196
00203 unsigned int headerSizeof(Header h, enum hMagic magicp)
00204 ;
00205
00211 Header headerLoad( void *p) ;
00212
00218 Header headerCopyLoad(void *p) ;
00219
00225 void * headerUnload(Header h)
00226 ;
00227
00235 Header headerReload( Header h, int tag)
00236 ;
00237
00242 Header headerNew(void) ;
00243
00249 Header headerLink(Header h)
00250 ;
00251
00256 void headerFree( Header h);
00257
00263 int headerUsageCount(Header h) ;
00264
00271 void headerDump(Header h, FILE *f, int flags,
00272 const struct headerTagTableEntry * tags);
00273 #define HEADER_DUMP_INLINE 1
00274
00275 typedef const char * errmsg_t;
00276
00288 char * headerSprintf(Header h, const char * fmt,
00289 const struct headerTagTableEntry * tags,
00290 const struct headerSprintfExtension * extentions,
00291 errmsg_t * errmsg)
00292 ;
00293
00308 int headerAddEntry(Header h, int_32 tag, int_32 type, const void *p, int_32 c)
00309 ;
00310
00321 int headerModifyEntry(Header h, int_32 tag, int_32 type, void *p, int_32 c)
00322 ;
00323
00330 char ** headerGetLangs(Header h) ;
00331
00352 int headerAddI18NString(Header h, int_32 tag, const char * string,
00353 const char * lang)
00354 ;
00355
00370 int headerAppendEntry(Header h, int_32 tag, int_32 type, void * p, int_32 c)
00371 ;
00372
00383 int headerAddOrAppendEntry(Header h, int_32 tag, int_32 type, void * p, int_32 c)
00384 ;
00385
00399 int headerGetEntry(Header h, int_32 tag, int_32 *type,
00400 void **p, int_32 *c)
00401 ;
00402
00415 int headerGetEntryMinMemory(Header h, int_32 tag, int_32 *type,
00416 const void **p, int_32 *c)
00417 ;
00418
00431 int headerGetRawEntry(Header h, int_32 tag, int_32 *type,
00432 const void **p, int_32 *c)
00433 ;
00434
00441 int headerIsEntry(Header h, int_32 tag) ;
00442
00452 int headerRemoveEntry(Header h, int_32 tag)
00453 ;
00454
00460 HeaderIterator headerInitIterator(Header h)
00461 ;
00462
00472 int headerNextIterator(HeaderIterator iter,
00473 int_32 * tag, int_32 * type,
00474 const void ** p, int_32 * c)
00475 ;
00476
00481 void headerFreeIterator( HeaderIterator iter);
00482
00488 Header headerCopy(Header h)
00489 ;
00490
00495 void headerSort(Header h)
00496 ;
00497
00502 void headerUnsort(Header h)
00503 ;
00504
00511 void headerCopyTags(Header headerFrom, Header headerTo, int_32 *tagstocopy)
00512 ;
00513
00517 typedef enum rpmTagType_e {
00518 #define RPM_MIN_TYPE 0
00519 RPM_NULL_TYPE = 0,
00520 RPM_CHAR_TYPE = 1,
00521 RPM_INT8_TYPE = 2,
00522 RPM_INT16_TYPE = 3,
00523 RPM_INT32_TYPE = 4,
00524
00525 RPM_STRING_TYPE = 6,
00526 RPM_BIN_TYPE = 7,
00527 RPM_STRING_ARRAY_TYPE = 8,
00528 RPM_I18NSTRING_TYPE = 9
00529 #define RPM_MAX_TYPE 9
00530 } rpmTagType;
00531
00538 static inline void * headerFreeData(
00539 const void * data, rpmTagType type)
00540 {
00541 if (data) {
00542 if (type < 0 ||
00543 type == RPM_STRING_ARRAY_TYPE ||
00544 type == RPM_I18NSTRING_TYPE ||
00545 type == RPM_BIN_TYPE)
00546 free((void *)data);
00547 }
00548 return NULL;
00549 }
00550
00559 typedef enum rpmSubTagType_e {
00560 RPM_REGION_TYPE = -10,
00561 RPM_BIN_ARRAY_TYPE = -11,
00564 RPM_XREF_TYPE = -12
00567 } rpmSubTagType;
00568
00573 #define HEADER_IMAGE 61
00574 #define HEADER_SIGNATURES 62
00575 #define HEADER_IMMUTABLE 63
00576 #define HEADER_REGIONS 64
00577 #define HEADER_I18NTABLE 100
00578 #define HEADER_SIGBASE 256
00579 #define HEADER_TAGBASE 1000
00580
00581 #ifdef __cplusplus
00582 }
00583 #endif
00584
00585 #endif