1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/rpm/BinHeader.cc
17 #define RPM_NULL_TYPE rpmTagType(0)
20 #ifndef _RPM_4_4_COMPAT
22 typedef rpmuint32_t rpm_count_t;
24 typedef int32_t rpm_count_t;
31 #include "zypp/base/Logger.h"
33 #include "zypp/target/rpm/BinHeader.h"
38 #define Y2LOG "BinHeader"
47 ///////////////////////////////////////////////////////////////////
49 // CLASS NAME : BinHeader::intList
51 ///////////////////////////////////////////////////////////////////
53 BinHeader::intList::intList()
54 : cnt( 0 ), val( 0 ), type( RPM_NULL_TYPE )
57 unsigned BinHeader::intList::set( void * val_r, unsigned cnt_r, rpmTagType type_r )
60 cnt = val ? cnt_r : 0;
65 int BinHeader::intList::operator[]( const unsigned idx_r ) const
71 #if RPM_CHAR_TYPE != RPM_INT8_TYPE
73 return ((char*)val)[idx_r];
76 return ((int8_t*)val)[idx_r];
78 return ((int16_t*)val)[idx_r];
80 return ((int32_t*)val)[idx_r];
86 ///////////////////////////////////////////////////////////////////
88 // CLASS NAME : BinHeader::stringList
90 ///////////////////////////////////////////////////////////////////
92 void BinHeader::stringList::clear()
100 BinHeader::stringList::stringList()
104 unsigned BinHeader::stringList::set( char ** val_r, unsigned cnt_r )
108 cnt = val ? cnt_r : 0;
112 std::string BinHeader::stringList::operator[]( const unsigned idx_r ) const
114 return( idx_r < cnt ? val[idx_r] : "" );
117 ///////////////////////////////////////////////////////////////////
119 // CLASS NAME : BinHeader
121 ///////////////////////////////////////////////////////////////////
123 ///////////////////////////////////////////////////////////////////
126 // METHOD NAME : BinHeader::BinHeader
127 // METHOD TYPE : Constructor
129 BinHeader::BinHeader( Header h_r )
138 ///////////////////////////////////////////////////////////////////
141 // METHOD NAME : BinHeader::BinHeader
142 // METHOD TYPE : Constructor
144 BinHeader::BinHeader( BinHeader::Ptr & rhs )
146 INT << "INJECT from " << rhs;
147 if ( ! (rhs && rhs->_h) )
153 _h = rhs->_h; // ::headerLink already done in rhs
156 INT << ": " << *this << " (" << rhs << ")" << endl;
159 ///////////////////////////////////////////////////////////////////
162 // METHOD NAME : BinHeader::~BinHeader
163 // METHOD TYPE : Destructor
165 BinHeader::~BinHeader()
173 ///////////////////////////////////////////////////////////////////
176 // METHOD NAME : BinHeader::assertHeader
177 // METHOD TYPE : void
179 bool BinHeader::assertHeader()
186 INT << "OOPS: NULL HEADER created!" << endl;
193 ///////////////////////////////////////////////////////////////////
196 // METHOD NAME : BinHeader::has_tag
197 // METHOD TYPE : bool
201 bool BinHeader::has_tag( tag tag_r ) const
203 return( !empty() && ::headerIsEntry( _h, tag_r ) );
206 ///////////////////////////////////////////////////////////////////
209 // METHOD NAME : BinHeader::int_list
210 // METHOD TYPE : unsigned
214 unsigned BinHeader::int_list( tag tag_r, intList & lst_r ) const
218 rpmTagType type = RPM_NULL_TYPE;
221 ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
228 return lst_r.set( 0, 0, type );
229 #if RPM_CHAR_TYPE != RPM_INT8_TYPE
235 return lst_r.set( val, cnt, type );
237 case RPM_STRING_ARRAY_TYPE:
241 INT << "RPM_TAG MISSMATCH: RPM_INT32_TYPE " << tag_r << " got type " << type << endl;
245 return lst_r.set( 0, 0, RPM_NULL_TYPE );
248 ///////////////////////////////////////////////////////////////////
251 // METHOD NAME : BinHeader::string_list
252 // METHOD TYPE : unsigned
256 unsigned BinHeader::string_list( tag tag_r, stringList & lst_r ) const
260 rpmTagType type = RPM_NULL_TYPE;
263 ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
270 return lst_r.set( 0, 0 );
271 case RPM_STRING_ARRAY_TYPE:
272 return lst_r.set( (char**)val, cnt );
275 INT << "RPM_TAG MISSMATCH: RPM_STRING_ARRAY_TYPE " << tag_r << " got type " << type << endl;
279 return lst_r.set( 0, 0 );
282 ///////////////////////////////////////////////////////////////////
285 // METHOD NAME : BinHeader::int_val
290 int BinHeader::int_val( tag tag_r ) const
294 rpmTagType type = RPM_NULL_TYPE;
297 ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
305 #if RPM_CHAR_TYPE != RPM_INT8_TYPE
307 return *((char*)val);
310 return *((int8_t*)val);
312 return *((int16_t*)val);
314 return *((int32_t*)val);
316 case RPM_STRING_ARRAY_TYPE:
320 INT << "RPM_TAG MISSMATCH: RPM_INT32_TYPE " << tag_r << " got type " << type << endl;
327 ///////////////////////////////////////////////////////////////////
330 // METHOD NAME : BinHeader::string_val
331 // METHOD TYPE : std::string
335 std::string BinHeader::string_val( tag tag_r ) const
339 rpmTagType type = RPM_NULL_TYPE;
342 ::headerGetEntry( _h, tag_r, hTYP_t(&type), &val, &cnt );
350 case RPM_STRING_TYPE:
353 case RPM_STRING_ARRAY_TYPE:
357 INT << "RPM_TAG MISSMATCH: RPM_STRING_TYPE " << tag_r << " got type " << type << endl;
364 ///////////////////////////////////////////////////////////////////
367 // METHOD NAME : BinHeader::stringList_val
368 // METHOD TYPE : std::list<std::string>
372 std::list<std::string> BinHeader::stringList_val( tag tag_r ) const
374 std::list<std::string> ret;
379 unsigned count = string_list( tag_r, lines );
380 for ( unsigned i = 0; i < count; ++i )
382 ret.push_back( lines[i] );
388 ///////////////////////////////////////////////////////////////////
391 // METHOD NAME : BinHeader::dumpOn
392 // METHOD TYPE : ostream &
396 ostream & BinHeader::dumpOn( ostream & str ) const
398 ReferenceCounted::dumpOn( str );
399 return str << '{' << (void*)_h << '}';
403 } // namespace target