1 /*@-type@*/ /* FIX: cast to HV_t bogus */
6 * \file lib/hdrinline.h
12 /*@+voidabstract -nullpass -mustmod -compdef -shadow -predboolothers @*/
15 * Header methods for rpm headers.
17 /*@observer@*/ /*@unchecked@*/
18 extern struct HV_s * hdrVec;
22 /*@unused@*/ static inline HV_t h2hv(Header h)
25 /*@-abstract -castexpose -refcounttrans@*/
27 /*@=abstract =castexpose =refcounttrans@*/
31 * Create new (empty) header instance.
34 /*@unused@*/ static inline
35 Header headerNew(void)
38 return hdrVec->hdrnew();
42 * Dereference a header instance.
43 * @todo Remove debugging entry from the ABI.
50 /*@unused@*/ static inline
51 /*@null@*/ Header XheaderFree( /*@killref@*/ /*@null@*/ Header h,
52 /*@null@*/ const char * msg, const char * fn, unsigned ln)
56 if (h == NULL) return NULL;
58 return (h2hv(h)->Xhdrfree) (h, msg, fn, ln);
62 * Reference a header instance.
63 * @todo Remove debugging entry from the ABI.
68 * @return new header reference
70 /*@unused@*/ static inline
71 Header XheaderLink(Header h, /*@null@*/ const char * msg,
72 const char * fn, unsigned ln)
75 return (h2hv(h)->Xhdrlink) (h, msg, fn, ln);
79 * Dereference a header instance.
80 * @todo Remove debugging entry from the ABI.
85 * @return new header reference
87 /*@unused@*/ static inline
88 Header XheaderUnlink(/*@killref@*/ /*@null@*/ Header h,
89 /*@null@*/ const char * msg, const char * fn, unsigned ln)
93 if (h == NULL) return NULL;
95 return (h2hv(h)->Xhdrunlink) (h, msg, fn, ln);
100 * Sort tags in header.
103 /*@unused@*/ static inline
104 void headerSort(Header h)
107 /*@-noeffectuncon@*/ /* FIX: add rc */
108 (h2hv(h)->hdrsort) (h);
114 * Restore tags in header to original ordering.
117 /*@unused@*/ static inline
118 void headerUnsort(Header h)
121 /*@-noeffectuncon@*/ /* FIX: add rc */
122 (h2hv(h)->hdrunsort) (h);
129 * Return size of on-disk header representation in bytes.
131 * @param magicp include size of 8 bytes for (magic, 0)?
132 * @return size of on-disk header
134 /*@unused@*/ static inline
135 unsigned int headerSizeof(/*@null@*/ Header h, enum hMagic magicp)
139 if (h == NULL) return 0;
141 return (h2hv(h)->hdrsizeof) (h, magicp);
145 * Convert header to on-disk representation.
146 * @param h header (with pointers)
147 * @return on-disk header blob (i.e. with offsets)
149 /*@unused@*/ static inline
150 /*@only@*/ /*@null@*/ void * headerUnload(Header h)
153 return (h2hv(h)->hdrunload) (h);
157 * Convert header to on-disk representation, and then reload.
158 * This is used to insure that all header data is in one chunk.
159 * @param h header (with pointers)
160 * @param tag region tag
161 * @return on-disk header (with offsets)
163 /*@unused@*/ static inline
164 /*@null@*/ Header headerReload(/*@only@*/ Header h, int tag)
168 return (h2hv(h)->hdrreload) (h, tag);
173 * Duplicate a header.
175 * @return new header instance
177 /*@unused@*/ static inline
178 /*@null@*/ Header headerCopy(Header h)
181 return (h2hv(h)->hdrcopy) (h);
185 * Convert header to in-memory representation.
186 * @param uh on-disk header blob (i.e. with offsets)
189 /*@unused@*/ static inline
190 /*@null@*/ Header headerLoad(/*@kept@*/ void * uh)
193 return hdrVec->hdrload(uh);
197 * Make a copy and convert header to in-memory representation.
198 * @param uh on-disk header blob (i.e. with offsets)
201 /*@unused@*/ static inline
202 /*@null@*/ Header headerCopyLoad(const void * uh)
205 return hdrVec->hdrcopyload(uh);
209 * Read (and load) header from file handle.
210 * @param fd file handle
211 * @param magicp read (and verify) 8 bytes of (magic, 0)?
212 * @return header (or NULL on error)
214 /*@unused@*/ static inline
215 /*@null@*/ Header headerRead(FD_t fd, enum hMagic magicp)
218 return hdrVec->hdrread(fd, magicp);
222 * Write (with unload) header to file handle.
223 * @param fd file handle
225 * @param magicp prefix write with 8 bytes of (magic, 0)?
226 * @return 0 on success, 1 on error
228 /*@unused@*/ static inline
229 int headerWrite(FD_t fd, /*@null@*/ Header h, enum hMagic magicp)
230 /*@modifies fd, h @*/
233 if (h == NULL) return 0;
235 return (h2hv(h)->hdrwrite) (fd, h, magicp);
239 * Check if tag is in header.
242 * @return 1 on success, 0 on failure
244 /*@unused@*/ static inline
245 int headerIsEntry(/*@null@*/ Header h, int_32 tag)
249 if (h == NULL) return 0;
251 return (h2hv(h)->hdrisentry) (h, tag);
255 * Free data allocated when retrieved from header.
257 * @param data address of data (or NULL)
258 * @param type type of data (or -1 to force free)
259 * @return NULL always
261 /*@unused@*/ static inline
262 /*@null@*/ void * headerFreeTag(Header h,
263 /*@only@*/ /*@null@*/ const void * data, rpmTagType type)
266 return (h2hv(h)->hdrfreetag) (h, data, type);
270 * Retrieve tag value.
271 * Will never return RPM_I18NSTRING_TYPE! RPM_STRING_TYPE elements with
272 * RPM_I18NSTRING_TYPE equivalent entries are translated (if HEADER_I18NTABLE
277 * @retval type address of tag value data type (or NULL)
278 * @retval p address of pointer to tag value(s) (or NULL)
279 * @retval c address of number of values (or NULL)
280 * @return 1 on success, 0 on failure
282 /*@unused@*/ static inline
283 int headerGetEntry(Header h, int_32 tag,
284 /*@null@*/ /*@out@*/ hTYP_t type,
285 /*@null@*/ /*@out@*/ void ** p,
286 /*@null@*/ /*@out@*/ hCNT_t c)
287 /*@modifies *type, *p, *c @*/
289 return (h2hv(h)->hdrget) (h, tag, type, p, c);
293 * Retrieve tag value using header internal array.
294 * Get an entry using as little extra RAM as possible to return the tag value.
295 * This is only an issue for RPM_STRING_ARRAY_TYPE.
299 * @retval type address of tag value data type (or NULL)
300 * @retval p address of pointer to tag value(s) (or NULL)
301 * @retval c address of number of values (or NULL)
302 * @return 1 on success, 0 on failure
304 /*@unused@*/ static inline
305 int headerGetEntryMinMemory(Header h, int_32 tag,
306 /*@null@*/ /*@out@*/ hTYP_t type,
307 /*@null@*/ /*@out@*/ hPTR_t * p,
308 /*@null@*/ /*@out@*/ hCNT_t c)
309 /*@modifies *type, *p, *c @*/
311 return (h2hv(h)->hdrgetmin) (h, tag, type, p, c);
316 * Duplicate tags are okay, but only defined for iteration (with the
317 * exceptions noted below). While you are allowed to add i18n string
318 * arrays through this function, you probably don't mean to. See
319 * headerAddI18NString() instead.
323 * @param type tag value data type
324 * @param p pointer to tag value(s)
325 * @param c number of values
326 * @return 1 on success, 0 on failure
329 /*@unused@*/ static inline
330 int headerAddEntry(Header h, int_32 tag, int_32 type, const void * p, int_32 c)
333 return (h2hv(h)->hdradd) (h, tag, type, p, c);
337 * Append element to tag array in header.
338 * Appends item p to entry w/ tag and type as passed. Won't work on
339 * RPM_STRING_TYPE. Any pointers into header memory returned from
340 * headerGetEntryMinMemory() for this entry are invalid after this
341 * call has been made!
345 * @param type tag value data type
346 * @param p pointer to tag value(s)
347 * @param c number of values
348 * @return 1 on success, 0 on failure
350 /*@unused@*/ static inline
351 int headerAppendEntry(Header h, int_32 tag, int_32 type,
352 const void * p, int_32 c)
355 return (h2hv(h)->hdrappend) (h, tag, type, p, c);
359 * Add or append element to tag array in header.
360 * @todo Arg "p" should have const.
363 * @param type tag value data type
364 * @param p pointer to tag value(s)
365 * @param c number of values
366 * @return 1 on success, 0 on failure
368 /*@unused@*/ static inline
369 int headerAddOrAppendEntry(Header h, int_32 tag, int_32 type,
370 const void * p, int_32 c)
373 return (h2hv(h)->hdraddorappend) (h, tag, type, p, c);
377 * Add locale specific tag to header.
378 * A NULL lang is interpreted as the C locale. Here are the rules:
380 * - If the tag isn't in the header, it's added with the passed string
382 * - If the tag occurs multiple times in entry, which tag is affected
383 * by the operation is undefined.
384 * - If the tag is in the header w/ this language, the entry is
385 * *replaced* (like headerModifyEntry()).
387 * This function is intended to just "do the right thing". If you need
388 * more fine grained control use headerAddEntry() and headerModifyEntry().
392 * @param string tag value
394 * @return 1 on success, 0 on failure
396 /*@unused@*/ static inline
397 int headerAddI18NString(Header h, int_32 tag, const char * string,
401 return (h2hv(h)->hdraddi18n) (h, tag, string, lang);
405 * Modify tag in header.
406 * If there are multiple entries with this tag, the first one gets replaced.
409 * @param type tag value data type
410 * @param p pointer to tag value(s)
411 * @param c number of values
412 * @return 1 on success, 0 on failure
414 /*@unused@*/ static inline
415 int headerModifyEntry(Header h, int_32 tag, int_32 type,
416 const void * p, int_32 c)
419 return (h2hv(h)->hdrmodify) (h, tag, type, p, c);
423 * Delete tag in header.
424 * Removes all entries of type tag from the header, returns 1 if none were
429 * @return 0 on success, 1 on failure (INCONSISTENT)
431 /*@unused@*/ static inline
432 int headerRemoveEntry(Header h, int_32 tag)
435 return (h2hv(h)->hdrremove) (h, tag);
439 * Return formatted output string from header tags.
440 * The returned string must be free()d.
443 * @param fmt format to use
444 * @param tbltags array of tag name/value pairs
445 * @param extensions chained table of formatting extensions.
446 * @retval errmsg error message (if any)
447 * @return formatted output string (malloc'ed)
449 /*@unused@*/ static inline
450 /*@only@*/ char * headerSprintf(Header h, const char * fmt,
451 const struct headerTagTableEntry_s * tbltags,
452 const struct headerSprintfExtension_s * extensions,
453 /*@null@*/ /*@out@*/ errmsg_t * errmsg)
454 /*@modifies *errmsg @*/
456 return (h2hv(h)->hdrsprintf) (h, fmt, tbltags, extensions, errmsg);
460 * Duplicate tag values from one header into another.
461 * @param headerFrom source header
462 * @param headerTo destination header
463 * @param tagstocopy array of tags that are copied
465 /*@unused@*/ static inline
466 void headerCopyTags(Header headerFrom, Header headerTo, hTAG_t tagstocopy)
467 /*@modifies headerFrom, headerTo @*/
469 /*@-noeffectuncon@*/ /* FIX: add rc */
470 hdrVec->hdrcopytags(headerFrom, headerTo, tagstocopy);
476 * Destroy header tag iterator.
477 * @param hi header tag iterator
478 * @return NULL always
480 /*@unused@*/ static inline
481 HeaderIterator headerFreeIterator(/*@only@*/ HeaderIterator hi)
484 return hdrVec->hdrfreeiter(hi);
488 * Create header tag iterator.
490 * @return header tag iterator
492 /*@unused@*/ static inline
493 HeaderIterator headerInitIterator(Header h)
496 return hdrVec->hdrinititer(h);
500 * Return next tag from header.
501 * @param hi header tag iterator
502 * @retval tag address of tag
503 * @retval type address of tag value data type
504 * @retval p address of pointer to tag value(s)
505 * @retval c address of number of values
506 * @return 1 on success, 0 on failure
508 /*@unused@*/ static inline
509 int headerNextIterator(HeaderIterator hi,
510 /*@null@*/ /*@out@*/ hTAG_t tag,
511 /*@null@*/ /*@out@*/ hTYP_t type,
512 /*@null@*/ /*@out@*/ hPTR_t * p,
513 /*@null@*/ /*@out@*/ hCNT_t c)
514 /*@modifies hi, *tag, *type, *p, *c @*/
516 return hdrVec->hdrnextiter(hi, tag, type, p, c);
519 /*@=voidabstract =nullpass =mustmod =compdef =shadow =predboolothers @*/
525 #endif /* H_HDRINLINE */