OSDN Git Service

Discontinue formal use of the build-aux submodule.
[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, 2013, MinGW.org 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 #if IMPLEMENTATION_LEVEL == PACKAGE_BASE_COMPONENT
36
37 EXTERN_C void pkgInstall( pkgActionItem* );
38 EXTERN_C void pkgRegister( pkgXmlNode*, pkgXmlNode*, const char*, const char* );
39 EXTERN_C void pkgRemove( pkgActionItem* );
40
41 class pkgManifest
42 {
43   /* A wrapper around the XML document class, with specialised methods
44    * for management of the package installation manifest.
45    */
46   public:
47     pkgManifest( const char*, const char* );
48     ~pkgManifest();
49
50     void AddEntry( const char*, const char* );
51     void BindSysRoot( pkgXmlNode*, const char* );
52     void DetachSysRoot( const char* );
53
54     inline pkgXmlNode *GetRoot(){ return manifest->GetRoot(); }
55     pkgXmlNode *GetSysRootReference( const char* );
56
57   private:
58     pkgXmlDocument *manifest;
59     pkgXmlNode     *inventory;
60 };
61
62 #endif /* PACKAGE_BASE_COMPONENT */
63
64 class pkgArchiveProcessor
65 {
66   /* A minimal generic abstract base class, from which we derive
67    * processing tools for handling arbitrary package architectures.
68    */
69   public:
70     pkgArchiveProcessor():save_on_extract(true){}
71     virtual ~pkgArchiveProcessor(){}
72
73     virtual bool IsOk() = 0;
74     virtual int Process() = 0;
75
76     inline void SaveExtractedFiles( bool mode ){ save_on_extract = mode; }
77     inline int SetOutputStream( const char *, int );
78
79   protected:
80     int sysroot_len;
81
82     /* Pointers to the sysroot management records and installation
83      * path template for a managed package; note that 'tarname' does
84      * not explicitly refer only to tar archives; it is simply the
85      * canonical name of the archive file, as recorded in the XML
86      * 'tarname' property of the package identifier record.
87      */
88     pkgXmlNode  *origin;
89     pkgXmlNode  *sysroot;
90     const char  *sysroot_path;
91     pkgManifest *installed;
92     const char  *tarname;
93     const char  *pkgfile;
94
95     virtual int CreateExtractionDirectory( const char* );
96     virtual int ExtractFile( int, const char*, int );
97
98     bool save_on_extract;
99 };
100
101 /* Our standard package format specifies the use of tar archives;
102  * the following specialisation of pkgArchiveProcessor provides the
103  * tools we need for processing such archives.
104  *
105  */
106 union tar_archive_header
107 {
108   /* Layout specification for the tar archive header records,
109    * one of which is associated with each individual data entity
110    * stored within a tar archive.
111    */
112   char aggregate[512];                  /* aggregate size is always 512 bytes */
113   struct tar_header_field_layout
114   {
115     char name[100];                     /* archive entry path name */
116     char mode[8];                       /* unix access mode for archive entry */
117     char uid[8];                        /* user id of archive entry's owner */
118     char gid[8];                        /* group id of archive entry's owner */
119     char size[12];                      /* size of archive entry in bytes */
120     char mtime[12];                     /* last modification time of entry */
121     char chksum[8];                     /* checksum for this header block */
122     char typeflag[1];                   /* type of this archive entry */
123     char linkname[100];                 /* if a link, name of linked file */
124     char magic[6];                      /* `magic' signature for the archive */
125     char version[2];                    /* specification conformance code */
126     char uname[32];                     /* user name of archive entry's owner */
127     char gname[32];                     /* group name of entry's owner */
128     char devmajor[8];                   /* device entity major number */
129     char devminor[8];                   /* device entity minor number */
130     char prefix[155];                   /* prefix to extend "name" field */
131   } field;
132 };
133
134 /* Type descriptors, as used in the `typeflag' field of the above
135  * tar archive header records; (note: this is not a comprehensive
136  * list, but covers all of, and more than, our requirements).
137  */
138 #define TAR_ENTITY_TYPE_FILE            '0'
139 #define TAR_ENTITY_TYPE_LINK            '1'
140 #define TAR_ENTITY_TYPE_SYMLINK         '2'
141 #define TAR_ENTITY_TYPE_CHRDEV          '3'
142 #define TAR_ENTITY_TYPE_BLKDEV          '4'
143 #define TAR_ENTITY_TYPE_DIRECTORY       '5'
144 #define TAR_ENTITY_TYPE_GNU_LONGNAME    'L'
145
146 /* Some older style tar archives may use '\0' as an alternative to '0',
147  * to identify an archive entry representing a regular file.
148  */
149 #define TAR_ENTITY_TYPE_ALTFILE         '\0'
150
151 /* Specify classification codes for tar archive processing errors.
152  */
153 #define TAR_ARCHIVE_DATA_READ_ERROR     -1
154 #define TAR_ARCHIVE_DATA_WRITE_ERROR    -2
155 #define TAR_ARCHIVE_FORMAT_ERROR        -3
156
157 class pkgTarArchiveProcessor : public pkgArchiveProcessor
158 {
159   /* An abstract base class, from which various tar archive
160    * processing tools, (including installers and uninstallers),
161    * are derived; this class implements the generic methods,
162    * which are shared by all such tools.
163    */
164   public:
165     /* Constructors and destructor...
166      */
167     pkgTarArchiveProcessor(){}
168     pkgTarArchiveProcessor( pkgXmlNode* );
169     virtual ~pkgTarArchiveProcessor();
170
171     inline bool IsOk(){ return stream->IsReady(); }
172     virtual int Process();
173
174   protected:
175     /* Class data...
176      */
177     pkgArchiveStream *stream;
178     union tar_archive_header header;
179
180     /* Internal archive processing methods...
181      * These are divided into two categories: those for which the
182      * abstract base class furnishes a generic implementation...
183      */
184     virtual int GetArchiveEntry();
185     virtual int ProcessEntityData( int );
186     virtual char *EntityDataAsString();
187
188     /* ...those for which each specialisation is expected to
189      * furnish its own task specific implementation...
190      */
191     virtual int ProcessDirectory( const char* ) = 0;
192     virtual int ProcessDataStream( const char* ) = 0;
193
194     /* ...and those which would normally be specialised, but
195      * for which we currently provide a generic stub...
196      */
197     virtual int ProcessLinkedEntity( const char* );
198 };
199
200 class pkgTarArchiveExtractor : public pkgTarArchiveProcessor
201 {
202   /* Worker class supporting extraction of tar archives to an
203    * arbitrary directory, without performing an installation.
204    */
205   public:
206     pkgTarArchiveExtractor( const char*, const char* );
207
208   private:
209     /* Specialised implementations of the archive processing methods...
210      */
211     virtual int ProcessDirectory( const char* );
212     virtual int ProcessDataStream( const char* );
213 };
214
215 #if IMPLEMENTATION_LEVEL == PACKAGE_BASE_COMPONENT
216
217 class pkgTarArchiveInstaller : public pkgTarArchiveProcessor
218 {
219   /* Worker class for extraction of package tar archive content
220    * to the sysroot directory nominated in the package manifest,
221    * for the purpose of performing an installation or upgrade.
222    */
223   public:
224     /* Constructor and destructor...
225      */
226     pkgTarArchiveInstaller( pkgXmlNode* );
227     virtual ~pkgTarArchiveInstaller(){}
228
229     virtual int Process();
230
231   private:
232     /* Specialised implementations of the archive processing methods...
233      */
234     virtual int ProcessDirectory( const char* );
235     virtual int ProcessDataStream( const char* );
236 };
237
238 class pkgTarArchiveUninstaller : public pkgTarArchiveProcessor
239 {
240   /* Worker class for removing package content which has been
241    * previously installed by the pkgTarArchiveInstaller.
242    */
243   public:
244     /* Constructor and destructor...
245      */
246     pkgTarArchiveUninstaller( pkgXmlNode* );
247     virtual ~pkgTarArchiveUninstaller(){};
248
249   private:
250     /* Specialised implementations of the archive processing methods...
251      */
252     virtual int ProcessDirectory( const char* );
253     virtual int ProcessDataStream( const char* );
254 };
255
256 #endif /* PACKAGE_BASE_COMPONENT */
257 #endif /* PKGPROC_H: $RCSfile$: end of file */