1 /*
2  *  package.h
3  *
4  *  Copyright (c) 2006-2018 Pacman Development Team <pacman-dev@archlinux.org>
5  *  Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6  *  Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7  *  Copyright (c) 2006 by David Kimpe <dnaku@frugalware.org>
8  *  Copyright (c) 2005, 2006 by Christian Hamar <krics@linuxforum.hu>
9  *  Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 #ifndef ALPM_PACKAGE_H
25 #define ALPM_PACKAGE_H
26 
27 #include <sys/types.h> /* off_t */
28 
29 /* libarchive */
30 #include <archive.h>
31 #include <archive_entry.h>
32 
33 #include "alpm.h"
34 #include "backup.h"
35 #include "db.h"
36 #include "signing.h"
37 
38 /** Package operations struct. This struct contains function pointers to
39  * all methods used to access data in a package to allow for things such
40  * as lazy package initialization (such as used by the file backend). Each
41  * backend is free to define a stuct containing pointers to a specific
42  * implementation of these methods. Some backends may find using the
43  * defined default_pkg_ops struct to work just fine for their needs.
44  */
45 struct pkg_operations {
46 	const char *(*get_base) (alpm_pkg_t *);
47 	const char *(*get_desc) (alpm_pkg_t *);
48 	const char *(*get_url) (alpm_pkg_t *);
49 	alpm_time_t (*get_builddate) (alpm_pkg_t *);
50 	alpm_time_t (*get_installdate) (alpm_pkg_t *);
51 	const char *(*get_packager) (alpm_pkg_t *);
52 	const char *(*get_arch) (alpm_pkg_t *);
53 	off_t (*get_isize) (alpm_pkg_t *);
54 	alpm_pkgreason_t (*get_reason) (alpm_pkg_t *);
55 	int (*get_validation) (alpm_pkg_t *);
56 	int (*has_scriptlet) (alpm_pkg_t *);
57 
58 	alpm_list_t *(*get_licenses) (alpm_pkg_t *);
59 	alpm_list_t *(*get_groups) (alpm_pkg_t *);
60 	alpm_list_t *(*get_depends) (alpm_pkg_t *);
61 	alpm_list_t *(*get_optdepends) (alpm_pkg_t *);
62 	alpm_list_t *(*get_checkdepends) (alpm_pkg_t *);
63 	alpm_list_t *(*get_makedepends) (alpm_pkg_t *);
64 	alpm_list_t *(*get_conflicts) (alpm_pkg_t *);
65 	alpm_list_t *(*get_provides) (alpm_pkg_t *);
66 	alpm_list_t *(*get_replaces) (alpm_pkg_t *);
67 	alpm_filelist_t *(*get_files) (alpm_pkg_t *);
68 	alpm_list_t *(*get_backup) (alpm_pkg_t *);
69 
70 	void *(*changelog_open) (alpm_pkg_t *);
71 	size_t (*changelog_read) (void *, size_t, const alpm_pkg_t *, void *);
72 	int (*changelog_close) (const alpm_pkg_t *, void *);
73 
74 	struct archive *(*mtree_open) (alpm_pkg_t *);
75 	int (*mtree_next) (const alpm_pkg_t *, struct archive *, struct archive_entry **);
76 	int (*mtree_close) (const alpm_pkg_t *, struct archive *);
77 
78 	int (*force_load) (alpm_pkg_t *);
79 };
80 
81 /** The standard package operations struct. get fields directly from the
82  * struct itself with no abstraction layer or any type of lazy loading.
83  * The actual definition is in package.c so it can have access to the
84  * default accessor functions which are defined there.
85  */
86 extern struct pkg_operations default_pkg_ops;
87 
88 struct __alpm_pkg_t {
89 	unsigned long name_hash;
90 	char *filename;
91 	char *base;
92 	char *name;
93 	char *version;
94 	char *desc;
95 	char *url;
96 	char *packager;
97 	char *md5sum;
98 	char *sha256sum;
99 	char *base64_sig;
100 	char *arch;
101 
102 	alpm_time_t builddate;
103 	alpm_time_t installdate;
104 
105 	off_t size;
106 	off_t isize;
107 	off_t download_size;
108 
109 	alpm_handle_t *handle;
110 
111 	alpm_list_t *licenses;
112 	alpm_list_t *replaces;
113 	alpm_list_t *groups;
114 	alpm_list_t *backup;
115 	alpm_list_t *depends;
116 	alpm_list_t *optdepends;
117 	alpm_list_t *checkdepends;
118 	alpm_list_t *makedepends;
119 	alpm_list_t *conflicts;
120 	alpm_list_t *provides;
121 	alpm_list_t *deltas;
122 	alpm_list_t *delta_path;
123 	alpm_list_t *removes; /* in transaction targets only */
124 	alpm_pkg_t *oldpkg; /* in transaction targets only */
125 
126 	struct pkg_operations *ops;
127 
128 	alpm_filelist_t files;
129 
130 	/* origin == PKG_FROM_FILE, use pkg->origin_data.file
131 	 * origin == PKG_FROM_*DB, use pkg->origin_data.db */
132 	union {
133 		alpm_db_t *db;
134 		char *file;
135 	} origin_data;
136 
137 	alpm_pkgfrom_t origin;
138 	alpm_pkgreason_t reason;
139 	int scriptlet;
140 
141 	/* Bitfield from alpm_dbinfrq_t */
142 	int infolevel;
143 	/* Bitfield from alpm_pkgvalidation_t */
144 	int validation;
145 };
146 
147 alpm_file_t *_alpm_file_copy(alpm_file_t *dest, const alpm_file_t *src);
148 
149 alpm_pkg_t *_alpm_pkg_new(void);
150 int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr);
151 void _alpm_pkg_free(alpm_pkg_t *pkg);
152 void _alpm_pkg_free_trans(alpm_pkg_t *pkg);
153 
154 int _alpm_pkg_validate_internal(alpm_handle_t *handle,
155 		const char *pkgfile, alpm_pkg_t *syncpkg, int level,
156 		alpm_siglist_t **sigdata, int *validation);
157 alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
158 		const char *pkgfile, int full);
159 
160 int _alpm_pkg_cmp(const void *p1, const void *p2);
161 int _alpm_pkg_compare_versions(alpm_pkg_t *local_pkg, alpm_pkg_t *pkg);
162 
163 #endif /* ALPM_PACKAGE_H */
164