OSDN Git Service

Support assignment of DEBUGLEVEL at configure time.
[mingw/mingw-get.git] / src / pkgproc.h
1 #ifndef PKGPROC_H
2 /*
3  * pkgproc.h
4  *
5  * $Id$
6  *
7  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8  * Copyright (C) 2009, 2010, 2011, MinGW Project
9  *
10  *
11  * Specifications for the internal architecture of package archives,
12  * and the public interface for the package archive processing routines,
13  * used to implement the package installer and uninstaller.
14  *
15  *
16  * This is free software.  Permission is granted to copy, modify and
17  * redistribute this software, under the provisions of the GNU General
18  * Public License, Version 3, (or, at your option, any later version),
19  * as published by the Free Software Foundation; see the file COPYING
20  * for licensing details.
21  *
22  * Note, in particular, that this software is provided "as is", in the
23  * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
24  * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
25  * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
26  * MinGW Project, accept liability for any damages, however caused,
27  * arising from the use of this software.
28  *
29  */
30 #define PKGPROC_H  1
31
32 #include "pkgbase.h"
33 #include "pkgstrm.h"
34
35 EXTERN_C void pkgInstall( pkgActionItem* );
36 EXTERN_C void pkgRegister( pkgXmlNode*, pkgXmlNode*, const char*, const char* );
37 EXTERN_C void pkgRemove( pkgActionItem* );
38
39 class pkgManifest
40 {
41   /* A wrapper around the XML document class, with specialised methods
42    * for management of the package installation manifest.
43    */
44   public:
45     pkgManifest( const char*, const char* );
46     ~pkgManifest();
47
48     void AddEntry( const char*, const char* );
49     void BindSysRoot( pkgXmlNode*, const char* );
50     void DetachSysRoot( const char* );
51
52     inline pkgXmlNode *GetRoot(){ return manifest->GetRoot(); }
53     pkgXmlNode *GetSysRootReference( const char* );
54
55   private:
56     pkgXmlDocument *manifest;
57     pkgXmlNode     *inventory;
58 };
59
60 class pkgArchiveProcessor
61 {
62   /* A minimal generic abstract base class, from which we derive
63    * processing tools for handling arbitrary package architectures.
64    */
65   public:
66     pkgArchiveProcessor(){}
67     virtual ~pkgArchiveProcessor(){}
68
69     virtual bool IsOk() = 0;
70     virtual int Process() = 0;
71
72   protected:
73     int sysroot_len;
74
75     /* Pointers to the sysroot management records and installation
76      * path template for a managed package; note that 'tarname' does
77      * not explicitly refer only to tar archives; it is simply the
78      * canonical name of the archive file, as recorded in the XML
79      * 'tarname' property of the package identifier record.
80      */
81     pkgXmlNode  *origin;
82     pkgXmlNode  *sysroot;
83     const char  *sysroot_path;
84     pkgManifest *installed;
85     const char  *tarname;
86     const char  *pkgfile;
87 };
88
89 /* Our standard package format specifies the use of tar archives;
90  * the following specialisation of pkgArchiveProcessor provides the
91  * tools we need for processing such archives.
92  *
93  */
94 union tar_archive_header
95 {
96   /* Layout specification for the tar archive header records,
97    * one of which is associated with each individual data entity
98    * stored within a tar archive.
99    */
100   char aggregate[512];                  /* aggregate size is always 512 bytes */
101   struct tar_header_field_layout
102   {
103     char name[100];                     /* archive entry path name */
104     char mode[8];                       /* unix access mode for archive entry */
105     char uid[8];                        /* user id of archive entry's owner */
106     char gid[8];                        /* group id of archive entry's owner */
107     char size[12];                      /* size of archive entry in bytes */
108     char mtime[12];                     /* last modification time of entry */
109     char chksum[8];                     /* checksum for this header block */
110     char typeflag[1];                   /* type of this archive entry */
111     char linkname[100];                 /* if a link, name of linked file */
112     char magic[6];                      /* `magic' signature for the archive */
113     char version[2];                    /* specification conformance code */
114     char uname[32];                     /* user name of archive entry's owner */
115     char gname[32];                     /* group name of entry's owner */
116     char devmajor[8];                   /* device entity major number */
117     char devminor[8];                   /* device entity minor number */
118     char prefix[155];                   /* prefix to extend "name" field */
119   } field;
120 };
121
122 /* Type descriptors, as used in the `typeflag' field of the above
123  * tar archive header records; (note: this is not a comprehensive
124  * list, but covers all of, and more than, our requirements).
125  */
126 #define TAR_ENTITY_TYPE_FILE            '0'
127 #define TAR_ENTITY_TYPE_LINK            '1'
128 #define TAR_ENTITY_TYPE_SYMLINK         '2'
129 #define TAR_ENTITY_TYPE_CHRDEV          '3'
130 #define TAR_ENTITY_TYPE_BLKDEV          '4'
131 #define TAR_ENTITY_TYPE_DIRECTORY       '5'
132 #define TAR_ENTITY_TYPE_GNU_LONGNAME    'L'
133
134 /* Some older style tar archives may use '\0' as an alternative to '0',
135  * to identify an archive entry representing a regular file.
136  */
137 #define TAR_ENTITY_TYPE_ALTFILE         '\0'
138
139 class pkgTarArchiveProcessor : public pkgArchiveProcessor
140 {
141   /* An abstract base class, from which various tar archive
142    * processing tools, (including installers and uninstallers),
143    * are derived; this class implements the generic methods,
144    * which are shared by all such tools.
145    */
146   public:
147     /* Constructor and destructor...
148      */
149     pkgTarArchiveProcessor( pkgXmlNode* );
150     virtual ~pkgTarArchiveProcessor();
151
152     inline bool IsOk(){ return stream->IsReady(); }
153     virtual int Process();
154
155   protected:
156     /* Class data...
157      */
158     pkgArchiveStream *stream;
159     union tar_archive_header header;
160
161     /* Internal archive processing methods...
162      * These are divided into two categories: those for which the
163      * abstract base class furnishes a generic implementation...
164      */
165     virtual int GetArchiveEntry();
166     virtual int ProcessEntityData( int );
167     virtual char *EntityDataAsString();
168
169     /* ...those for which each specialisation is expected to
170      * furnish its own task specific implementation...
171      */
172     virtual int ProcessDirectory( const char* ) = 0;
173     virtual int ProcessDataStream( const char* ) = 0;
174
175     /* ...and those which would normally be specialised, but
176      * for which we currently provide a generic stub...
177      */
178     virtual int ProcessLinkedEntity( const char* );
179 };
180
181 class pkgTarArchiveInstaller : public pkgTarArchiveProcessor
182 {
183   public:
184     /* Constructor and destructor...
185      */
186     pkgTarArchiveInstaller( pkgXmlNode* );
187     virtual ~pkgTarArchiveInstaller(){}
188
189     virtual int Process();
190
191   private:
192     /* Specialised implementations of the archive processing methods...
193      */
194     virtual int ProcessDirectory( const char* );
195     virtual int ProcessDataStream( const char* );
196 };
197
198 class pkgTarArchiveUninstaller : public pkgTarArchiveProcessor
199 {
200   public:
201     /* Constructor and destructor...
202      */
203     pkgTarArchiveUninstaller( pkgXmlNode* );
204     virtual ~pkgTarArchiveUninstaller(){};
205
206   private:
207     /* Specialised implementations of the archive processing methods...
208      */
209     virtual int ProcessDirectory( const char* );
210     virtual int ProcessDataStream( const char* );
211 };
212
213 #endif /* PKGPROC_H: $RCSfile$: end of file */