OSDN Git Service

Note relocation of m4 when packaging source distribution.
[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     virtual int CreateExtractionDirectory( const char* );
89     virtual int ExtractFile( int, const char*, int );
90 };
91
92 /* Our standard package format specifies the use of tar archives;
93  * the following specialisation of pkgArchiveProcessor provides the
94  * tools we need for processing such archives.
95  *
96  */
97 union tar_archive_header
98 {
99   /* Layout specification for the tar archive header records,
100    * one of which is associated with each individual data entity
101    * stored within a tar archive.
102    */
103   char aggregate[512];                  /* aggregate size is always 512 bytes */
104   struct tar_header_field_layout
105   {
106     char name[100];                     /* archive entry path name */
107     char mode[8];                       /* unix access mode for archive entry */
108     char uid[8];                        /* user id of archive entry's owner */
109     char gid[8];                        /* group id of archive entry's owner */
110     char size[12];                      /* size of archive entry in bytes */
111     char mtime[12];                     /* last modification time of entry */
112     char chksum[8];                     /* checksum for this header block */
113     char typeflag[1];                   /* type of this archive entry */
114     char linkname[100];                 /* if a link, name of linked file */
115     char magic[6];                      /* `magic' signature for the archive */
116     char version[2];                    /* specification conformance code */
117     char uname[32];                     /* user name of archive entry's owner */
118     char gname[32];                     /* group name of entry's owner */
119     char devmajor[8];                   /* device entity major number */
120     char devminor[8];                   /* device entity minor number */
121     char prefix[155];                   /* prefix to extend "name" field */
122   } field;
123 };
124
125 /* Type descriptors, as used in the `typeflag' field of the above
126  * tar archive header records; (note: this is not a comprehensive
127  * list, but covers all of, and more than, our requirements).
128  */
129 #define TAR_ENTITY_TYPE_FILE            '0'
130 #define TAR_ENTITY_TYPE_LINK            '1'
131 #define TAR_ENTITY_TYPE_SYMLINK         '2'
132 #define TAR_ENTITY_TYPE_CHRDEV          '3'
133 #define TAR_ENTITY_TYPE_BLKDEV          '4'
134 #define TAR_ENTITY_TYPE_DIRECTORY       '5'
135 #define TAR_ENTITY_TYPE_GNU_LONGNAME    'L'
136
137 /* Some older style tar archives may use '\0' as an alternative to '0',
138  * to identify an archive entry representing a regular file.
139  */
140 #define TAR_ENTITY_TYPE_ALTFILE         '\0'
141
142 class pkgTarArchiveProcessor : public pkgArchiveProcessor
143 {
144   /* An abstract base class, from which various tar archive
145    * processing tools, (including installers and uninstallers),
146    * are derived; this class implements the generic methods,
147    * which are shared by all such tools.
148    */
149   public:
150     /* Constructors and destructor...
151      */
152     pkgTarArchiveProcessor(){}
153     pkgTarArchiveProcessor( pkgXmlNode* );
154     virtual ~pkgTarArchiveProcessor();
155
156     inline bool IsOk(){ return stream->IsReady(); }
157     virtual int Process();
158
159   protected:
160     /* Class data...
161      */
162     pkgArchiveStream *stream;
163     union tar_archive_header header;
164
165     /* Internal archive processing methods...
166      * These are divided into two categories: those for which the
167      * abstract base class furnishes a generic implementation...
168      */
169     virtual int GetArchiveEntry();
170     virtual int ProcessEntityData( int );
171     virtual char *EntityDataAsString();
172
173     /* ...those for which each specialisation is expected to
174      * furnish its own task specific implementation...
175      */
176     virtual int ProcessDirectory( const char* ) = 0;
177     virtual int ProcessDataStream( const char* ) = 0;
178
179     /* ...and those which would normally be specialised, but
180      * for which we currently provide a generic stub...
181      */
182     virtual int ProcessLinkedEntity( const char* );
183 };
184
185 class pkgTarArchiveExtractor : public pkgTarArchiveProcessor
186 {
187   /* Worker class supporting extraction of tar archives to an
188    * arbitrary directory, without performing an installation.
189    */
190   public:
191     pkgTarArchiveExtractor( const char*, const char* );
192
193   private:
194     /* Specialised implementations of the archive processing methods...
195      */
196     virtual int ProcessDirectory( const char* );
197     virtual int ProcessDataStream( const char* );
198 };
199
200 class pkgTarArchiveInstaller : public pkgTarArchiveProcessor
201 {
202   /* Worker class for extraction of package tar archive content
203    * to the sysroot directory nominated in the package manifest,
204    * for the purpose of performing an installation or upgrade.
205    */
206   public:
207     /* Constructor and destructor...
208      */
209     pkgTarArchiveInstaller( pkgXmlNode* );
210     virtual ~pkgTarArchiveInstaller(){}
211
212     virtual int Process();
213
214   private:
215     /* Specialised implementations of the archive processing methods...
216      */
217     virtual int ProcessDirectory( const char* );
218     virtual int ProcessDataStream( const char* );
219 };
220
221 class pkgTarArchiveUninstaller : public pkgTarArchiveProcessor
222 {
223   /* Worker class for removing package content which has been
224    * previously installed by the pkgTarArchiveInstaller.
225    */
226   public:
227     /* Constructor and destructor...
228      */
229     pkgTarArchiveUninstaller( pkgXmlNode* );
230     virtual ~pkgTarArchiveUninstaller(){};
231
232   private:
233     /* Specialised implementations of the archive processing methods...
234      */
235     virtual int ProcessDirectory( const char* );
236     virtual int ProcessDataStream( const char* );
237 };
238
239 #endif /* PKGPROC_H: $RCSfile$: end of file */