7 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8 * Copyright (C) 2009, 2010, 2011, MinGW 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 EXTERN_C void pkgInstall( pkgActionItem* );
36 EXTERN_C void pkgRegister( pkgXmlNode*, pkgXmlNode*, const char*, const char* );
37 EXTERN_C void pkgRemove( pkgActionItem* );
41 /* A wrapper around the XML document class, with specialised methods
42 * for management of the package installation manifest.
45 pkgManifest( const char*, const char* );
48 void AddEntry( const char*, const char* );
49 void BindSysRoot( pkgXmlNode*, const char* );
50 void DetachSysRoot( const char* );
52 inline pkgXmlNode *GetRoot(){ return manifest->GetRoot(); }
53 pkgXmlNode *GetSysRootReference( const char* );
56 pkgXmlDocument *manifest;
57 pkgXmlNode *inventory;
60 class pkgArchiveProcessor
62 /* A minimal generic abstract base class, from which we derive
63 * processing tools for handling arbitrary package architectures.
66 pkgArchiveProcessor(){}
67 virtual ~pkgArchiveProcessor(){}
69 virtual bool IsOk() = 0;
70 virtual int Process() = 0;
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.
83 const char *sysroot_path;
84 pkgManifest *installed;
88 virtual int CreateExtractionDirectory( const char* );
89 virtual int ExtractFile( int, const char*, int );
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.
97 union tar_archive_header
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.
103 char aggregate[512]; /* aggregate size is always 512 bytes */
104 struct tar_header_field_layout
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 */
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).
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'
137 /* Some older style tar archives may use '\0' as an alternative to '0',
138 * to identify an archive entry representing a regular file.
140 #define TAR_ENTITY_TYPE_ALTFILE '\0'
142 class pkgTarArchiveProcessor : public pkgArchiveProcessor
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.
150 /* Constructors and destructor...
152 pkgTarArchiveProcessor(){}
153 pkgTarArchiveProcessor( pkgXmlNode* );
154 virtual ~pkgTarArchiveProcessor();
156 inline bool IsOk(){ return stream->IsReady(); }
157 virtual int Process();
162 pkgArchiveStream *stream;
163 union tar_archive_header header;
165 /* Internal archive processing methods...
166 * These are divided into two categories: those for which the
167 * abstract base class furnishes a generic implementation...
169 virtual int GetArchiveEntry();
170 virtual int ProcessEntityData( int );
171 virtual char *EntityDataAsString();
173 /* ...those for which each specialisation is expected to
174 * furnish its own task specific implementation...
176 virtual int ProcessDirectory( const char* ) = 0;
177 virtual int ProcessDataStream( const char* ) = 0;
179 /* ...and those which would normally be specialised, but
180 * for which we currently provide a generic stub...
182 virtual int ProcessLinkedEntity( const char* );
185 class pkgTarArchiveExtractor : public pkgTarArchiveProcessor
187 /* Worker class supporting extraction of tar archives to an
188 * arbitrary directory, without performing an installation.
191 pkgTarArchiveExtractor( const char*, const char* );
194 /* Specialised implementations of the archive processing methods...
196 virtual int ProcessDirectory( const char* );
197 virtual int ProcessDataStream( const char* );
200 class pkgTarArchiveInstaller : public pkgTarArchiveProcessor
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.
207 /* Constructor and destructor...
209 pkgTarArchiveInstaller( pkgXmlNode* );
210 virtual ~pkgTarArchiveInstaller(){}
212 virtual int Process();
215 /* Specialised implementations of the archive processing methods...
217 virtual int ProcessDirectory( const char* );
218 virtual int ProcessDataStream( const char* );
221 class pkgTarArchiveUninstaller : public pkgTarArchiveProcessor
223 /* Worker class for removing package content which has been
224 * previously installed by the pkgTarArchiveInstaller.
227 /* Constructor and destructor...
229 pkgTarArchiveUninstaller( pkgXmlNode* );
230 virtual ~pkgTarArchiveUninstaller(){};
233 /* Specialised implementations of the archive processing methods...
235 virtual int ProcessDirectory( const char* );
236 virtual int ProcessDataStream( const char* );
239 #endif /* PKGPROC_H: $RCSfile$: end of file */