Commit Graph

43 Commits

Author SHA1 Message Date
Panu Matilainen b287bdcadf Natively allocate main header related structs
There are many opportunities for using STL containers here, but
conversions are non-trivial.
2024-04-30 09:06:31 +03:00
Panu Matilainen a8ef47798e Add casts that C++ requires but C doesn't across librpm
The low level ndb engine is intentionally exempt here, leaving if/when
to maintainer discretion.
2024-04-09 11:00:00 +03:00
Panu Matilainen 8866314570 Fix int/enum type mixup in rpmtdType() and rpmtdClass() 2024-04-05 16:16:22 +03:00
Panu Matilainen 1c98b67911 Drop top-level source for our global include directories
Having everything accessible to everything encourages fast and loose
includes from places one shouldn't be using, and makes it easy for
those cases to hide in plain sight as well. There were reasons for
the top-level include back in 2007 but our codebase is a rather
different beast these days. Limiting access through per-target
include directories on everything nicely highlights the exceptions
and makes the whole more controllable and manageable.

This change looks huge, but it's just due to stripping no longer valid
prefixes from all the gazillion internal includes. No rpm-side
functionality is affected, this is just source-level hygiene operation.
2023-09-13 13:34:17 +03:00
Justus Winter c2ef4dd2a7 Include rpmpgp.h only where it is actually needed
Include necessary headers that were previously transitively included
by including rpmpgp.h.
2021-11-17 14:21:06 +02:00
Panu Matilainen c886b359ba Fix pointer dereference before testing for NULL in rpmtdGetNumber() 2020-02-06 15:32:54 +01:00
Panu Matilainen a8abf2cfd0 Eliminate the rest of idiotic assert()'s in rpmtd.c
Finish what was started in commit 9c979cffe9,
with greetings to self ten years ago...
2017-09-05 13:13:49 +03:00
Panu Matilainen 9c979cffe9 Eliminate a bunch of idiotic assert()'s in rpmtd getters
In the cases where zero is a sane return for non-existent data,
return it instead of barfing up an assert. Many more unnecessary
asserts left there but these are rather obvious...
2017-08-30 14:26:19 +03:00
Panu Matilainen d137a7b8c5 Free td data on rpmtdFree(), DOH
Hard to imagine what I've been thinking almost exactly nine years
ago when introducing this API that doesn't free its own data.
2017-05-26 12:36:38 +03:00
Panu Matilainen 7560d36d1a Eliminate dumb assert()'s on NULL pointers on rpmtdFreeData() etc
We can just as easily handle these nicely so lets do so...
2017-05-26 12:32:56 +03:00
Panu Matilainen 4393d0d5a9 Force header data formatting through a central function
Make rpmHeaderFormatFuncByName() and rpmHeaderFormatFuncByValue() return
an opaque pointer to the extension itself (instead of the actual function
pointer) and drop Func from the function and type names to signify the
point. Add rpmHeaderFormatCall() function through which all formatting
has to be done now.

This is not supposed to change anything in itself, but opens up
possibilities for central error checking etc.
2016-10-25 13:51:47 +03:00
Panu Matilainen cff6a5d991 Remember data (allocation) size of non-extension data from headerGet()
- Add size member to rpmtd_s and accessor function to get it.
  For now only works for data marked with RPMTD_IMMUTABLE.
- This is redundant for BIN type, but especially for string types this
  info is impossible to get without walking the entire data.
2014-10-24 10:03:39 +03:00
Panu Matilainen 0c76a514f0 Rename td2pool as rpmtdToPool, export and optimize
- Using rpmtd iteration for this is slow and stupid as we keep
  pointlessly re-re-re-re-re-validating the tag type and indexes.
- Change argument order to source -> destination
- Move to rpmtd.c where it belongs and make public with a decent
  name. Not sure if this is the kind of an API we really want to make
  public but ... at least for now it'll do.
2012-09-11 08:16:07 +03:00
Panu Matilainen b922b4392f Add getter for rpmtd flags
- While these are mostly of rpmtd-internal interest only, there are
  cases when caller might want to know...
2012-02-21 13:50:34 +02:00
Panu Matilainen 1f1e5e88a1 Handle query format field width centrally in formatValue()
- Eliminate the quirky formatPrefix buffer argument to formatter functions,
  deal with the width at formatValue() if specified.
- This not only simplifies things a great deal, removes a nasty
  unbounded buffer writing from formatter functions and speeds things
  up somewhat by removing extra rasprintf()'s in many cases, it also
  gives us width formatting of everything including "error messages"
  like "(none)" and "(not a number)" which previously got dumped without
  any formatting.
- The cost of this is the loss of zero padding support for numeric
  data but that's hardly a big deal.
2011-08-17 10:59:49 +03:00
Panu Matilainen 757d0b443b Switch header APIs to use rpmTagVal instead of rpmTag
- The header getters are used for both signature header and the "normal"
  header, and even beyond that there's no requirement for a tag in
  the header to be part of rpmTag enum. The headerPutFoo() variants
  technically do require the tag to be found in the tag table (ie be
  an rpmTag) but they still operate on the integer value, they dont
  require it to be a "true" enum.
- Inside tagexts.c there are a few "true" enum uses in the
  internal helper functions, leave them be.
- While this technically changes some the most commonly used API's,
  this wont affect callers really: if the callers were using an enum
  before, enum can always be cast naturally to an integer. The other
  way around was the problematic part (ie the braindamage we're fixing
  here now...)
2010-10-22 09:59:56 +03:00
Panu Matilainen be488096e0 Use the new tag type/return type getters everywhere
- Instead of masking and bitfiddling all over the place, use the
  new getters to get the exact (enum) type directly. rpmTagGetType()
  is now unused within rpm but leaving around for backwards compatibility
2010-09-21 12:40:33 +03:00
Panu Matilainen b0d62148a9 Use proper types for tag and format extension functions
- Stuff the tag prototypes into misc.h in lack of better place
- Actually use the headerTagFooFunction prototypes instead of void *
2010-09-21 12:23:18 +03:00
Panu Matilainen 381605a9bb Honor rpmtd type, not tag type, in rpmtdClass() (ticket #25) 2009-01-28 13:21:39 +02:00
Panu Matilainen 2db2c376b3 Add rpmtdGetNumber() for getting numeric values from tag container
- returns the value (as opposed to pointer to, like the rpmtdGetUint32()
  and the like do) of any numeric type as uint64_t (largest supported
  integer type so everything can be converted to it)
- handy when you don't really care what the internal presentation is
- there's no rpmtdGetNextNumber() as there's no meaningful way to return
  end-of-iteration here
2008-11-17 12:04:08 +02:00
Panu Matilainen ed5306b0be Introduce rpm tag "classes"
- rpm tag data can be either numeric, strings or binary data, each with
  their own "subclasses" (different sized integers etc), add new
  enumeration for these
- add rpmTagGetClass(), rpmtdClass() public functions for retrieving the
  base class of tag and container
- useful for getting a basic idea how to handle tag/container data
2008-11-17 11:31:00 +02:00
Panu Matilainen 9b162540e1 Add rpmtdFromUint8()
- handles CHAR, INT8 and BIN types
2008-06-18 12:36:20 +03:00
Panu Matilainen 2f55856c85 Make rpmtdFromStringArray() data argument const afterall
- produces somewhat less warnings as is, a bit surprisingly
2008-06-17 16:04:12 +03:00
Panu Matilainen f4cdf53a76 Add rpmtdFrom() methods for 16 and 64 bit types 2008-06-17 14:24:16 +03:00
Panu Matilainen 61f096c11e Add some new rpmtd creation methods
- rpmtdFromString(), rpmtdFromStringArray() and rpmtdFromUint32() permit
  populating tag containers of compatible datatypes that can be used for
  headerPut() with some extra type-safety and sanity checks on the types
2008-06-17 12:07:19 +03:00
Panu Matilainen 05db695ee6 Add access methods for 64bit integer types to rpmtd 2008-06-06 23:47:37 +03:00
Panu Matilainen 9c209c8a2d Add rpmtdGetIndex() + rpmtdSetIndex() methods 2008-05-23 17:07:34 +03:00
Panu Matilainen 9979407567 Add rpmtdSetTag() method for setting (or changing) container tag + type
- permit change on non-empty container to compatible type to allow things like
    headerGet(h, RPMTAG_FILENAMES, td, HEADERGET_EXT);
    rpmtdSetTag(td, RPMTAG_OLDFILENAMES);
    headerPut(h, td, HEADERPUT_DEFAULT);
- empty container can be set to any valid type
2008-05-23 17:07:34 +03:00
Panu Matilainen 35c0252857 Add per-datatype iterators to rpmtd
- just uint32 and string iterators for now, those are the most common ones
- allows somewhat more convenient code constructs when type is known,
  eg no need to separately check for non-null inside loops
2008-05-21 14:49:12 +03:00
Panu Matilainen 1c80801ab6 Misplaced assert
- we only care about non-NULL data if we're supposed to free the contents
2008-05-21 12:41:31 +03:00
Panu Matilainen ce70ac8717 Add rpmtdDup() method for deep copying of tag containers 2008-05-21 12:04:51 +03:00
Panu Matilainen 34151a9e35 Turn rpmtd freeData into flag bitfield, allowing more precise control
- headerGet() returns even array data in a single allocation block, but
  regular (string) arrays need to have the pointers in array freed too
- set immutable flag on header data
2008-05-21 12:04:51 +03:00
Panu Matilainen a9920b9299 Fix up for RPM_BIN_TYPE td->count abuse just once, in rpmtdCount() 2008-05-21 12:04:51 +03:00
Panu Matilainen fc38b84c01 Lose the useless rpmtdToString()
- either use rpmtdFormat() or xstrdup() on rpmtdGetString() as appropriate
2008-05-21 12:04:51 +03:00
Panu Matilainen fae1edeb93 Lose padding argument from formatters
- formatPrefix already contains the padding, just use rasprintf() on that
  to get properly allocated buffer without messing with it manually
- xml format doesn't honor padding anyway so don't bother with it
2008-05-21 12:04:50 +03:00
Panu Matilainen 9b32e58e17 Add rpmtdFormat() method and enumeration of supported formats
- permits formatting any rpmtd data to our supported formats over
  iteration
2008-05-21 12:04:50 +03:00
Panu Matilainen d5381c16a7 Handle RPM_CHAR_TYPE too in stringFormat()
- used by filestates and nothing else apparently, duh..
2008-05-21 12:04:50 +03:00
Panu Matilainen 75f62d7c5f Teach rpmtd about the raw i18n string (array) type 2008-05-19 08:27:10 +03:00
Panu Matilainen 30c4e29d33 Add some more rpmtd access methods
- rpmtdGetUint() for 16 and 32 bit integer types, similar to
  rpmtdGetString() (equally usable with scalar types and arrays)
- rpmtdToString() which converts "any" header data into string presentation
2008-05-13 18:09:35 +03:00
Panu Matilainen 11980a42f2 Add methods to construct tag containers from argv and argi arrays
- basic type checking done based on tag (return) type
2008-05-13 16:11:28 +03:00
Panu Matilainen 9de4354a12 Add support for iterating over tag data container
- rpmtd iterator init + next methods
- string accessor method for RPM_STRING_TYPE and RPM_STRING_ARRAY_TYPE
2008-05-13 14:40:55 +03:00
Panu Matilainen 223da12f24 Add rpmtdTag() method 2008-05-13 14:02:40 +03:00
Panu Matilainen a83cfce188 New "tag data" container struct + some basic methods to deal with it
- to be used for passing around header and extension data
- inspired by similar changes in rpm5.org, details and implementation differ
2008-05-13 11:02:45 +03:00