7 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8 * Copyright (C) 2009, 2010, 2011, 2013, MinGW.org Project
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.
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.
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.
35 #if IMPLEMENTATION_LEVEL == PACKAGE_BASE_COMPONENT
37 EXTERN_C void pkgInstall( pkgActionItem* );
38 EXTERN_C void pkgRegister( pkgXmlNode*, pkgXmlNode*, const char*, const char* );
39 EXTERN_C void pkgRemove( pkgActionItem* );
43 /* A wrapper around the XML document class, with specialised methods
44 * for management of the package installation manifest.
47 pkgManifest( const char*, const char* );
50 void AddEntry( const char*, const char* );
51 void BindSysRoot( pkgXmlNode*, const char* );
52 void DetachSysRoot( const char* );
54 inline pkgXmlNode *GetRoot(){ return manifest->GetRoot(); }
55 pkgXmlNode *GetSysRootReference( const char* );
58 pkgXmlDocument *manifest;
59 pkgXmlNode *inventory;
62 #endif /* PACKAGE_BASE_COMPONENT */
64 class pkgArchiveProcessor
66 /* A minimal generic abstract base class, from which we derive
67 * processing tools for handling arbitrary package architectures.
70 pkgArchiveProcessor():save_on_extract(true){}
71 virtual ~pkgArchiveProcessor(){}
73 virtual bool IsOk() = 0;
74 virtual int Process() = 0;
76 inline void SaveExtractedFiles( bool mode ){ save_on_extract = mode; }
77 inline int SetOutputStream( const char *, int );
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.
90 const char *sysroot_path;
91 pkgManifest *installed;
95 virtual int CreateExtractionDirectory( const char* );
96 virtual int ExtractFile( int, const char*, int );
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.
106 union tar_archive_header
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.
112 char aggregate[512]; /* aggregate size is always 512 bytes */
113 struct tar_header_field_layout
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 */
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).
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'
146 /* Some older style tar archives may use '\0' as an alternative to '0',
147 * to identify an archive entry representing a regular file.
149 #define TAR_ENTITY_TYPE_ALTFILE '\0'
151 /* Specify classification codes for tar archive processing errors.
153 #define TAR_ARCHIVE_DATA_READ_ERROR -1
154 #define TAR_ARCHIVE_DATA_WRITE_ERROR -2
155 #define TAR_ARCHIVE_FORMAT_ERROR -3
157 class pkgTarArchiveProcessor : public pkgArchiveProcessor
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.
165 /* Constructors and destructor...
167 pkgTarArchiveProcessor(){}
168 pkgTarArchiveProcessor( pkgXmlNode* );
169 virtual ~pkgTarArchiveProcessor();
171 inline bool IsOk(){ return stream->IsReady(); }
172 virtual int Process();
177 pkgArchiveStream *stream;
178 union tar_archive_header header;
180 /* Internal archive processing methods...
181 * These are divided into two categories: those for which the
182 * abstract base class furnishes a generic implementation...
184 virtual int GetArchiveEntry();
185 virtual int ProcessEntityData( int );
186 virtual char *EntityDataAsString();
188 /* ...those for which each specialisation is expected to
189 * furnish its own task specific implementation...
191 virtual int ProcessDirectory( const char* ) = 0;
192 virtual int ProcessDataStream( const char* ) = 0;
194 /* ...and those which would normally be specialised, but
195 * for which we currently provide a generic stub...
197 virtual int ProcessLinkedEntity( const char* );
200 class pkgTarArchiveExtractor : public pkgTarArchiveProcessor
202 /* Worker class supporting extraction of tar archives to an
203 * arbitrary directory, without performing an installation.
206 pkgTarArchiveExtractor( const char*, const char* );
209 /* Specialised implementations of the archive processing methods...
211 virtual int ProcessDirectory( const char* );
212 virtual int ProcessDataStream( const char* );
215 #if IMPLEMENTATION_LEVEL == PACKAGE_BASE_COMPONENT
217 class pkgTarArchiveInstaller : public pkgTarArchiveProcessor
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.
224 /* Constructor and destructor...
226 pkgTarArchiveInstaller( pkgXmlNode* );
227 virtual ~pkgTarArchiveInstaller(){}
229 virtual int Process();
232 /* Specialised implementations of the archive processing methods...
234 virtual int ProcessDirectory( const char* );
235 virtual int ProcessDataStream( const char* );
238 class pkgTarArchiveUninstaller : public pkgTarArchiveProcessor
240 /* Worker class for removing package content which has been
241 * previously installed by the pkgTarArchiveInstaller.
244 /* Constructor and destructor...
246 pkgTarArchiveUninstaller( pkgXmlNode* );
247 virtual ~pkgTarArchiveUninstaller(){};
250 /* Specialised implementations of the archive processing methods...
252 virtual int ProcessDirectory( const char* );
253 virtual int ProcessDataStream( const char* );
256 #endif /* PACKAGE_BASE_COMPONENT */
257 #endif /* PKGPROC_H: $RCSfile$: end of file */