Go to the documentation of this file.
4 #ifndef tools_rroot_key
5 #define tools_rroot_key
28 void csz__Init_Inflate(
long,
unsigned char*,
long,
unsigned char*);
30 unsigned char* csz__obufptr();
38 static uint32 class_version() {
return 2;}
43 return uint32(x.size()+
sizeof(
unsigned char)+
sizeof(
int));
45 return uint32(x.size()+
sizeof(
unsigned char));
49 key(std::ostream& a_out)
67 mem::increment(
s_class().c_str());
91 mem::increment(
s_class().c_str());
96 m_out <<
"tools::rroot::key::key(cpcstor) :"
97 <<
" can't alloc " << a_nbytes <<
"."
106 mem::decrement(
s_class().c_str());
127 mem::increment(
s_class().c_str());
132 m_out <<
"tools::rroot::key::key(cpcstor) :"
133 <<
" can't alloc " << a_from.
m_buf_size <<
"."
143 if(&a_from==
this)
return *
this;
163 m_out <<
"tools::rroot::key::operator=() :"
164 <<
" can't alloc " << a_from.
m_buf_size <<
"."
191 m_out <<
"tools::rroot::key::read_file :"
192 <<
" reading " <<
m_nbytes <<
" bytes"
206 bool from_buffer(
bool a_byte_swap,
const char* aEOB,
char*& a_pos,
bool a_verbose) {
209 if(!rb.
read(_nbytes))
return false;
229 if(!rb.
read(v))
return false;
232 if(!rb.
read(_date))
return false;
235 if(!rb.
read(v))
return false;
238 if(!rb.
read(v))
return false;
245 if(!rb.
read(i))
return false;
248 if(!rb.
read(i))
return false;
255 m_out <<
"tools::rroot::key::from_buffer :"
269 m_out <<
"tools::rroot::key::get_object_buffer :"
270 <<
" WARNING : m_key_length is zero."
279 m_out <<
"tools::rroot::key::get_object_buffer :"
280 <<
" m_nbytes is zero."
289 m_out <<
"tools::rroot::key::get_object_buffer :"
290 <<
" WARNING : m_object_size is zero."
295 m_out <<
"tools::rroot::key::get_object_buffer :"
307 m_out <<
"tools::rroot::key::get_object_buffer :"
308 <<
" WARNING : m_buf_size<m_nbytes."
311 <<
". Raise m_buf_size to " <<
m_nbytes <<
"."
317 m_out <<
"tools::rroot::key::get_object_buffer :"
338 char* decbuf =
new char[decsiz];
340 m_out <<
"tools::rroot::key::get_object_buffer :"
341 <<
" can't alloc " << decsiz
363 unsigned char* objbuf = (
unsigned char*)(decbuf+
m_key_length);
368 int nin = 9 + ((int)bufcur[3] | ((
int)bufcur[4] << 8) | ((
int)bufcur[5] << 16));
369 int nbuf = (int)bufcur[6] | ((
int)bufcur[7] << 8) | ((
int)bufcur[8] << 16);
370 if(!
unzip(
m_out,a_file,nin,bufcur,nbuf,objbuf,nout))
break;
383 m_out <<
"tools::rroot::key::get_object_buffer :"
384 <<
" nothing from decompression."
392 m_out <<
"tools::rroot::key::get_object_buffer :"
393 <<
" decompression mismatch."
394 <<
" noutot " << noutot
411 void dump(std::ostream& a_out)
const {
426 _nbytes +=
sizeof(short);
428 _nbytes +=
sizeof(
date);
432 _nbytes +=
sizeof(
seek);
433 _nbytes +=
sizeof(
seek);
435 _nbytes +=
sizeof(
seek32);
436 _nbytes +=
sizeof(
seek32);
446 int a_srcsize,
unsigned char* a_src,
int a_tgtsize,
unsigned char* a_tgt,
int& a_irep) {
460 const int HDRSIZE = 9;
462 if (a_srcsize < HDRSIZE) {
463 a_out <<
"tools::rroot::key::unzip : too small source" << std::endl;
467 unsigned char DEFLATE = 8;
469 if ((a_src[0] !=
'C' && a_src[0] !=
'Z') ||
470 (a_src[1] !=
'S' && a_src[1] !=
'L') ||
471 a_src[2] != DEFLATE) {
472 a_out <<
"tools::rroot::key::unzip : error in header" << std::endl;
476 long _ibufcnt = (long)a_src[3] | ((
long)a_src[4] << 8) | ((
long)a_src[5] << 16);
477 long isize = (long)a_src[6] | ((
long)a_src[7] << 8) | ((
long)a_src[8] << 16);
479 if(a_tgtsize<isize) {
480 a_out <<
"tools::rroot::key::unzip : too small target." << std::endl;
484 if(_ibufcnt + HDRSIZE != a_srcsize) {
485 a_out <<
"tools::rroot::key::unzip :"
486 <<
" discrepancy in source length." << std::endl;
492 if (a_src[0] ==
'Z' && a_src[1] ==
'L') {
494 if(!a_file.
unziper(
'Z',func)) {
495 a_out <<
"tools::rroot::key::unzip : "
496 <<
" zlib unziper not found." << std::endl;
501 char* src = (
char*)(a_src + HDRSIZE);
503 (
unsigned int)a_srcsize,src,
504 (
unsigned int)a_tgtsize,(
char*)a_tgt,irep)) {
505 a_out <<
"tools::rroot::key::unzip : "
506 <<
" unzip function failed." << std::endl;
513 }
else if (a_src[0] ==
'C' && a_src[1] ==
'S') {
516 csz__Init_Inflate(_ibufcnt,a_src + HDRSIZE,a_tgtsize,a_tgt);
518 if (csz__Inflate()) {
519 a_out <<
"tools::rroot::key::unzip :"
520 <<
" error during decompression." << std::endl;
524 unsigned char* obufptr = csz__obufptr();
528 if (obufptr - a_tgt > a_tgtsize) {
529 a_out <<
"tools::rroot::key::_unzip :"
530 <<
" discrepancy " << (int)(obufptr - a_tgt)
531 <<
" with initial size: " << (int)isize
532 <<
", tgtsize= " << a_tgtsize
534 a_irep = int(obufptr - a_tgt);
543 a_out <<
"tools::rroot::key::_unzip : unknown a_src[0,1]."
544 <<
" [0] = " << a_src[0] <<
", [1] = " << a_src[1]
553 static const std::string s_v(
"tools::rroot::key");