1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/rpm/BinHeader.cc
15 #ifndef _RPM_4_4_COMPAT
16 typedef int32_t rpm_count_t;
22 #include "zypp/base/Logger.h"
24 #include "zypp/target/rpm/BinHeader.h"
29 #define Y2LOG "BinHeader"
38 ///////////////////////////////////////////////////////////////////
40 // CLASS NAME : BinHeader::intList
42 ///////////////////////////////////////////////////////////////////
44 BinHeader::intList::intList()
45 : cnt( 0 ), val( 0 ), type( RPM_NULL_TYPE )
48 unsigned BinHeader::intList::set( void * val_r, unsigned cnt_r, rpmTagType type_r )
51 cnt = val ? cnt_r : 0;
56 int BinHeader::intList::operator[]( const unsigned idx_r ) const
63 return ((char*)val)[idx_r];
65 return ((int8_t*)val)[idx_r];
67 return ((int16_t*)val)[idx_r];
69 return ((int32_t*)val)[idx_r];
75 ///////////////////////////////////////////////////////////////////
77 // CLASS NAME : BinHeader::stringList
79 ///////////////////////////////////////////////////////////////////
81 void BinHeader::stringList::clear()
89 BinHeader::stringList::stringList()
93 unsigned BinHeader::stringList::set( char ** val_r, unsigned cnt_r )
97 cnt = val ? cnt_r : 0;
101 std::string BinHeader::stringList::operator[]( const unsigned idx_r ) const
103 return( idx_r < cnt ? val[idx_r] : "" );
106 ///////////////////////////////////////////////////////////////////
108 // CLASS NAME : BinHeader
110 ///////////////////////////////////////////////////////////////////
112 ///////////////////////////////////////////////////////////////////
115 // METHOD NAME : BinHeader::BinHeader
116 // METHOD TYPE : Constructor
118 BinHeader::BinHeader( Header h_r )
127 ///////////////////////////////////////////////////////////////////
130 // METHOD NAME : BinHeader::BinHeader
131 // METHOD TYPE : Constructor
133 BinHeader::BinHeader( BinHeader::Ptr & rhs )
135 INT << "INJECT from " << rhs;
136 if ( ! (rhs && rhs->_h) )
142 _h = rhs->_h; // ::headerLink already done in rhs
145 INT << ": " << *this << " (" << rhs << ")" << endl;
148 ///////////////////////////////////////////////////////////////////
151 // METHOD NAME : BinHeader::~BinHeader
152 // METHOD TYPE : Destructor
154 BinHeader::~BinHeader()
162 ///////////////////////////////////////////////////////////////////
165 // METHOD NAME : BinHeader::assertHeader
166 // METHOD TYPE : void
168 bool BinHeader::assertHeader()
175 INT << "OOPS: NULL HEADER created!" << endl;
182 ///////////////////////////////////////////////////////////////////
185 // METHOD NAME : BinHeader::has_tag
186 // METHOD TYPE : bool
190 bool BinHeader::has_tag( tag tag_r ) const
192 return( !empty() && ::headerIsEntry( _h, tag_r ) );
195 ///////////////////////////////////////////////////////////////////
198 // METHOD NAME : BinHeader::int_list
199 // METHOD TYPE : unsigned
203 unsigned BinHeader::int_list( tag tag_r, intList & lst_r ) const
207 rpmTagType type = RPM_NULL_TYPE;
210 ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
217 return lst_r.set( 0, 0, type );
222 return lst_r.set( val, cnt, type );
224 case RPM_STRING_ARRAY_TYPE:
228 INT << "RPM_TAG MISSMATCH: RPM_INT32_TYPE " << tag_r << " got type " << type << endl;
232 return lst_r.set( 0, 0, RPM_NULL_TYPE );
235 ///////////////////////////////////////////////////////////////////
238 // METHOD NAME : BinHeader::string_list
239 // METHOD TYPE : unsigned
243 unsigned BinHeader::string_list( tag tag_r, stringList & lst_r ) const
247 rpmTagType type = RPM_NULL_TYPE;
250 ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
257 return lst_r.set( 0, 0 );
258 case RPM_STRING_ARRAY_TYPE:
259 return lst_r.set( (char**)val, cnt );
262 INT << "RPM_TAG MISSMATCH: RPM_STRING_ARRAY_TYPE " << tag_r << " got type " << type << endl;
266 return lst_r.set( 0, 0 );
269 ///////////////////////////////////////////////////////////////////
272 // METHOD NAME : BinHeader::int_val
277 int BinHeader::int_val( tag tag_r ) const
281 rpmTagType type = RPM_NULL_TYPE;
284 ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
293 return *((char*)val);
295 return *((int8_t*)val);
297 return *((int16_t*)val);
299 return *((int32_t*)val);
301 case RPM_STRING_ARRAY_TYPE:
305 INT << "RPM_TAG MISSMATCH: RPM_INT32_TYPE " << tag_r << " got type " << type << endl;
312 ///////////////////////////////////////////////////////////////////
315 // METHOD NAME : BinHeader::string_val
316 // METHOD TYPE : std::string
320 std::string BinHeader::string_val( tag tag_r ) const
324 rpmTagType type = RPM_NULL_TYPE;
327 ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
335 case RPM_STRING_TYPE:
338 case RPM_STRING_ARRAY_TYPE:
342 INT << "RPM_TAG MISSMATCH: RPM_STRING_TYPE " << tag_r << " got type " << type << endl;
349 ///////////////////////////////////////////////////////////////////
352 // METHOD NAME : BinHeader::stringList_val
353 // METHOD TYPE : std::list<std::string>
357 std::list<std::string> BinHeader::stringList_val( tag tag_r ) const
359 std::list<std::string> ret;
364 unsigned count = string_list( tag_r, lines );
365 for ( unsigned i = 0; i < count; ++i )
367 ret.push_back( lines[i] );
373 ///////////////////////////////////////////////////////////////////
376 // METHOD NAME : BinHeader::dumpOn
377 // METHOD TYPE : ostream &
381 ostream & BinHeader::dumpOn( ostream & str ) const
383 ReferenceCounted::dumpOn( str );
384 return str << '{' << (void*)_h << '}';
388 } // namespace target