summaryrefslogtreecommitdiff
path: root/apt-pkg/deb/debfile.h
blob: 21c59a5679cf6942148858a4e9b8198132ee8fcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
/* ######################################################################

   Debian Archive File (.deb)

   This Class handles all the operations performed directly on .deb 
   files. It makes use of the AR and TAR classes to give the necessary
   external interface.
   
   There are only two things that can be done with a raw package, 
   extract it's control information and extract the contents itself. 

   This should probably subclass an as-yet unwritten super class to
   produce a generic archive mechanism.
  
   The memory control file extractor is useful to extract a single file
   into memory from the control.tar.gz
   
   ##################################################################### */
									/*}}}*/
#ifndef PKGLIB_DEBFILE_H
#define PKGLIB_DEBFILE_H

#include <apt-pkg/arfile.h>
#include <apt-pkg/dirstream.h>
#include <apt-pkg/macros.h>
#include <apt-pkg/tagfile.h>

#include <string>

#ifndef APT_8_CLEANER_HEADERS
#include <apt-pkg/md5.h>
#endif
#ifndef APT_10_CLEANER_HEADERS
#include <apt-pkg/pkgcache.h>
#endif

class FileFd;

class debDebFile
{
   protected:
   
   FileFd &File;
   ARArchive AR;
   
   bool CheckMember(const char *Name);
   
   public:
   class ControlExtract;
   class MemControlExtract;

   bool ExtractTarMember(pkgDirStream &Stream, const char *Name);
   bool ExtractArchive(pkgDirStream &Stream);
   const ARArchive::Member *GotoMember(const char *Name);
   inline FileFd &GetFile() {return File;};
   
   explicit debDebFile(FileFd &File);
};

class debDebFile::ControlExtract : public pkgDirStream
{
   public:
   
   virtual bool DoItem(Item &Itm,int &Fd) APT_OVERRIDE;
};

class debDebFile::MemControlExtract : public pkgDirStream
{
   bool IsControl;
   
   public:
   
   char *Control;
   pkgTagSection Section;
   unsigned long Length;
   std::string Member;
   
   // Members from DirStream
   virtual bool DoItem(Item &Itm,int &Fd) APT_OVERRIDE;
   virtual bool Process(Item &Itm,const unsigned char *Data,
			unsigned long long Size,unsigned long long Pos) APT_OVERRIDE;

   // Helpers
   bool Read(debDebFile &Deb);
   bool TakeControl(const void *Data,unsigned long long Size);

   MemControlExtract() : IsControl(false), Control(0), Length(0), Member("control") {};
   explicit MemControlExtract(std::string Member) : IsControl(false), Control(0), Length(0), Member(Member) {};
   ~MemControlExtract() {delete [] Control;};   
};
									/*}}}*/

#endif