1 // KDat - a tar-based DAT archiver
2 // Copyright (C) 1998-2000 Sean Vyain, svyain@mail.tds.net
3 // Copyright (C) 2001-2002 Lawrence Widman, kdat@cardiothink.com
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "TarParser.h"
21 #include "TarParser.moc"
23 TarParser::TarParser()
33 void TarParser::slotData( const char * data
, int length
)
35 for ( int i
= 0; i
< length
; i
++ ) {
36 if ( _bufIdx
>= 512 ) {
37 if ( _blocksToSkip
> 0 ) {
39 record
* rec
= (record
*)_buf
;
40 _extended
= rec
->ext_hdr
.isextended
;
44 memcpy( _archname
+ _archnameIdx
, _buf
, 512 );
54 _buf
[_bufIdx
++] = data
[i
];
58 int TarParser::parseOctal( const char* buf
, int length
)
62 for ( int i
= 0; i
< length
; i
++ ) {
64 if ( ( buf
[i
] >= '1' ) && ( buf
[i
] <= '7' ) ) {
72 void TarParser::parseTarBlock()
74 record
* rec
= (record
*)_buf
;
77 printf( "----- parsing tar block -----\n" );
78 printf( "arch_name = '%s'\n", rec
->header
.arch_name
);
79 printf( "mode = '%s'\n", rec
->header
.mode
);
80 printf( "uid = %d\n", parseOctal( rec
->header
.uid
, 6 ) );
81 printf( "gid = %d\n", parseOctal( rec
->header
.gid
, 6 ) );
82 printf( "size = %d\n", parseOctal( rec
->header
.size
, 11 ) );
83 printf( "mtime = %d\n", parseOctal( rec
->header
.mtime
, 11 ) );
84 printf( "chksum = '%s'\n", rec
->header
.chksum
);
85 printf( "linkflag = '%c'\n", rec
->header
.linkflag
);
86 printf( "arch_linkname = '%s'\n", rec
->header
.arch_linkname
);
87 printf( "magic = '%s'\n", rec
->header
.magic
);
88 printf( "uname = '%s'\n", rec
->header
.uname
);
89 printf( "gname = '%s'\n", rec
->header
.gname
);
90 printf( "devmajor = %d\n", parseOctal( rec
->header
.devmajor
, 8 ) );
91 printf( "devminor = %d\n", parseOctal( rec
->header
.devminor
, 8 ) );
92 printf( "atime = %d\n", parseOctal( rec
->header
.atime
, 11 ) );
93 printf( "ctime = %d\n", parseOctal( rec
->header
.ctime
, 11 ) );
94 printf( "offset = %d\n", parseOctal( rec
->header
.offset
, 11 ) );
95 printf( "longnames = '%s'\n", rec
->header
.longnames
);
96 printf( "isextended = %d\n", rec
->header
.isextended
);
97 printf( "realsize = %d\n", parseOctal( rec
->header
.realsize
, 11 ) );
100 if ( rec
->header
.magic
[0] != 0 ) {
101 _blocksToSkip
= ( parseOctal( rec
->header
.size
, 11 ) + 511 ) / 512;
102 _extended
= rec
->header
.isextended
;
104 if ( rec
->header
.linkflag
== LF_LONGNAME
) {
105 // The actual file name is stored in the next _blocksToSkip blocks of the tar-file.
111 emit
sigEntry( _archname
, parseOctal( rec
->header
.size
, 11 ), parseOctal( rec
->header
.mtime
, 11 ), _record
);
113 emit
sigEntry( rec
->header
.arch_name
, parseOctal( rec
->header
.size
, 11 ), parseOctal( rec
->header
.mtime
, 11 ), _record
);