home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / misc / src / rpm / lib / header.h < prev    next >
C/C++ Source or Header  |  1997-09-17  |  5KB  |  169 lines

  1. /* RPM - Copyright (C) 1995 Red Hat Software
  2.  * 
  3.  * header.h - routines for managing rpm tagged structures
  4.  */
  5.  
  6. /* WARNING: 1 means success, 0 means failure (yes, this is backwards) */
  7.  
  8. #ifndef H_HEADER
  9. #define H_HEADER
  10. #include <stdio.h>
  11.  
  12. #if defined(__alpha__)
  13. typedef long int int_64;
  14. typedef int int_32;
  15. typedef short int int_16;
  16. typedef char int_8;
  17.  
  18. typedef unsigned int uint_32;
  19. typedef unsigned short uint_16;
  20.  
  21. #else
  22.  
  23. typedef long long int int_64;
  24. typedef int int_32;
  25. typedef short int int_16;
  26. typedef char int_8;
  27.  
  28. typedef unsigned int uint_32;
  29. typedef unsigned short uint_16;
  30. #endif
  31.  
  32. typedef struct headerToken *Header;
  33. typedef struct headerIteratorS *HeaderIterator;
  34.  
  35. struct headerTagTableEntry {
  36.     char * name;
  37.     int val;
  38. };
  39.  
  40. enum headerSprintfExtenstionType { HEADER_EXT_LAST = 0, HEADER_EXT_FORMAT,
  41.                    HEADER_EXT_MORE, HEADER_EXT_TAG };
  42.  
  43. /* This will only ever be passed RPM_TYPE_INT32 or RPM_TYPE_STRING to
  44.    help keep things simple */
  45. typedef char * (*headerTagFormatFunction)(int_32 type, const void * data, 
  46.                       char * formatPrefix,
  47.                       int padding, int element);
  48. typedef int (*headerTagTagFunction)(Header h, int_32 * type, void ** data,
  49.                        int_32 * count, int * freeData);
  50.  
  51. struct headerSprintfExtension {
  52.     enum headerSprintfExtenstionType type;
  53.     char * name;
  54.     union {
  55.     void * generic;
  56.     headerTagFormatFunction formatFunction;
  57.     headerTagTagFunction tagFunction;
  58.     struct headerSprintfExtension * more;
  59.     } u;
  60. };
  61.  
  62. /* This defines some basic conversions all header users would probably like
  63.    to have */
  64. extern const struct headerSprintfExtension headerDefaultFormats[];
  65.  
  66. /* read and write a header from a file */
  67. Header headerRead(int fd, int magicp);
  68. void headerWrite(int fd, Header h, int magicp);
  69. unsigned int headerSizeof(Header h, int magicp);
  70.  
  71. #define HEADER_MAGIC_NO   0
  72. #define HEADER_MAGIC_YES  1
  73.  
  74. /* load and unload a header from a chunk of memory */
  75. Header headerLoad(void *p);
  76. void *headerUnload(Header h);
  77.  
  78. Header headerNew(void);
  79. void headerFree(Header h);
  80.  
  81. /* dump a header to a file, in human readable format */
  82. void headerDump(Header h, FILE *f, int flags, 
  83.         const struct headerTagTableEntry * tags);
  84.  
  85. /* the returned string must be free()d */
  86. char * headerSprintf(Header h, const char * fmt, 
  87.              const struct headerTagTableEntry * tags,
  88.              const struct headerSprintfExtension * extentions,
  89.              char ** error);
  90.  
  91. #define HEADER_DUMP_INLINE   1
  92.  
  93. /* Duplicate tags are okay, but only defined for iteration (with the 
  94.    exceptions noted below). While you are allowed to add i18n string
  95.    arrays through this function, you probably don't mean to. See
  96.    headerAddI18NString() instead */
  97. int headerAddEntry(Header h, int_32 tag, int_32 type, void *p, int_32 c);
  98. int headerModifyEntry(Header h, int_32 tag, int_32 type, void *p, int_32 c);
  99.  
  100. /* For the C locale, lang should be *NULL*. Here are the rules:
  101.  
  102.     1) If the tag isn't in the Header, it's added with the passed string
  103.        as a version.
  104.     2) If the tag occurs multiple times in entry, which tag is affected
  105.        by the operation is undefined.
  106.     2) If the tag is in the header w/ this language, the entry is
  107.        *replaced* (like headerModifyEntry()).
  108.  
  109.    This function is intended to just "do the right thing". If you need
  110.    more fine grained control use headerAddEntry() and headerModifyEntry()
  111.    but be careful!
  112. */
  113. int headerAddI18NString(Header h, int_32 tag, char * string, char * lang);
  114.  
  115. /* Appends item p to entry w/ tag and type as passed. Won't work on
  116.    RPM_STRING_TYPE. Any pointers from headerGetEntry() for this entry
  117.    are invalid after this call has been made! */
  118. int headerAppendEntry(Header h, int_32 tag, int_32 type, void * p, int_32 c);
  119.  
  120. /* Will never return RPM_I18NSTRING_TYPE! RPM_STRING_TYPE elements w/
  121.    RPM_I18NSTRING_TYPE equivalent enreies are translated (if HEADER_I18NTABLE
  122.    entry is present). */
  123. int headerGetEntry(Header h, int_32 tag, int_32 *type, void **p, int_32 *c);
  124.  
  125. /* If *type is RPM_NULL_TYPE any type will match, otherwise only *type will
  126.    match. */
  127. int headerGetRawEntry(Header h, int_32 tag, int_32 *type, void **p, int_32 *c);
  128.  
  129. int headerIsEntry(Header h, int_32 tag);
  130. /* removes all entries of type tag from the header, returns 1 if none were
  131.    found */
  132. int headerRemoveEntry(Header h, int_32 tag);
  133.  
  134. HeaderIterator headerInitIterator(Header h);
  135. int headerNextIterator(HeaderIterator iter,
  136.                int_32 *tag, int_32 *type, void **p, int_32 *c);
  137. void headerFreeIterator(HeaderIterator iter);
  138.  
  139. /* reexamines LANGUAGE and LANG settings to set a new language for the
  140.    header; this only needs to be called if LANGUAGE or LANG may have changed
  141.    since the first headerGetEntry() on the header */
  142. void headerResetLang(Header h);
  143. /* sets the language path for the header; this doesn't need to be done if
  144.    the LANGUAGE or LANG enivronment variable are correct */
  145. void headerSetLangPath(Header h, char * lang);
  146.  
  147. Header headerCopy(Header h);
  148. void headerSort(Header h);
  149.  
  150. /* Entry Types */
  151.  
  152. #define RPM_NULL_TYPE        0
  153. #define RPM_CHAR_TYPE        1
  154. #define RPM_INT8_TYPE        2
  155. #define RPM_INT16_TYPE        3
  156. #define RPM_INT32_TYPE        4
  157. /* #define RPM_INT64_TYPE    5   ---- These aren't supported (yet) */
  158. #define RPM_STRING_TYPE        6
  159. #define RPM_BIN_TYPE        7
  160. #define RPM_STRING_ARRAY_TYPE    8
  161. #define RPM_I18NSTRING_TYPE    9
  162.  
  163. /* Tags -- general use tags should start at 1000 (RPM's tag space starts 
  164.    there) */
  165.  
  166. #define HEADER_I18NTABLE    100
  167.  
  168. #endif H_HEADER
  169.