dpkg (1.18.25) stretch; urgency=medium
[dpkg] / lib / dpkg / dpkg-db.h
CommitLineData
1479465f
GJ
1/*
2 * libdpkg - Debian packaging suite library routines
3 * dpkg-db.h - declarations for in-core package database management
4 *
5 * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2000,2001 Wichert Akkerman
7 * Copyright © 2006-2014 Guillem Jover <guillem@debian.org>
8 *
9 * This is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef LIBDPKG_DPKG_DB_H
24#define LIBDPKG_DPKG_DB_H
25
26#include <sys/types.h>
27
28#include <stdbool.h>
29#include <stdio.h>
30
31#include <dpkg/macros.h>
32#include <dpkg/varbuf.h>
33#include <dpkg/version.h>
34#include <dpkg/arch.h>
35
36DPKG_BEGIN_DECLS
37
38/**
39 * @defgroup dpkg-db In-core package database management
40 * @ingroup dpkg-public
41 * @{
42 */
43
44enum deptype {
45 dep_suggests,
46 dep_recommends,
47 dep_depends,
48 dep_predepends,
49 dep_breaks,
50 dep_conflicts,
51 dep_provides,
52 dep_replaces,
53 dep_enhances
54};
55
56struct dependency {
57 struct pkginfo *up;
58 struct dependency *next;
59 struct deppossi *list;
60 enum deptype type;
61};
62
63struct deppossi {
64 struct dependency *up;
65 struct pkgset *ed;
66 struct deppossi *next, *rev_next, *rev_prev;
67 const struct dpkg_arch *arch;
68 struct dpkg_version version;
69 enum dpkg_relation verrel;
70 bool arch_is_implicit;
71 bool cyclebreak;
72};
73
74struct arbitraryfield {
75 struct arbitraryfield *next;
76 const char *name;
77 const char *value;
78};
79
80struct conffile {
81 struct conffile *next;
82 const char *name;
83 const char *hash;
84 bool obsolete;
85};
86
87struct filedetails {
88 struct filedetails *next;
89 const char *name;
90 const char *msdosname;
91 const char *size;
92 const char *md5sum;
93};
94
95enum pkgmultiarch {
96 PKG_MULTIARCH_NO,
97 PKG_MULTIARCH_SAME,
98 PKG_MULTIARCH_ALLOWED,
99 PKG_MULTIARCH_FOREIGN,
100};
101
102/**
103 * Node describing a binary package file.
104 *
105 * This structure holds information contained on each binary package.
106 */
107struct pkgbin {
108 struct dependency *depends;
109 /** The ‘essential’ flag, true = yes, false = no (absent). */
110 bool essential;
111 enum pkgmultiarch multiarch;
112 const struct dpkg_arch *arch;
113 /** The following is the "pkgname:archqual" cached string, if this was a
114 * C++ class this member would be mutable. */
115 const char *pkgname_archqual;
116 const char *description;
117 const char *maintainer;
118 const char *source;
119 const char *installedsize;
120 const char *origin;
121 const char *bugs;
122 struct dpkg_version version;
123 struct conffile *conffiles;
124 struct arbitraryfield *arbs;
125};
126
127/**
128 * Node indicates that parent's Triggers-Pending mentions name.
129 *
130 * Note: These nodes do double duty: after they're removed from a package's
131 * trigpend list, references may be preserved by the trigger cycle checker
132 * (see trigproc.c).
133 */
134struct trigpend {
135 struct trigpend *next;
136 const char *name;
137};
138
139/**
140 * Node indicates that aw's Triggers-Awaited mentions pend.
141 */
142struct trigaw {
143 struct pkginfo *aw, *pend;
144 struct trigaw *samepend_next;
145 struct {
146 struct trigaw *next, *prev;
147 } sameaw;
148};
149
150/* Note: dselect and dpkg have different versions of this. */
151struct perpackagestate;
152
153enum pkgwant {
154 PKG_WANT_UNKNOWN,
155 PKG_WANT_INSTALL,
156 PKG_WANT_HOLD,
157 PKG_WANT_DEINSTALL,
158 PKG_WANT_PURGE,
159 /** Not allowed except as special sentinel value in some places. */
160 PKG_WANT_SENTINEL,
161};
162
163enum pkgeflag {
164 PKG_EFLAG_OK = 0,
165 PKG_EFLAG_REINSTREQ = 1,
166};
167
168enum pkgstatus {
169 PKG_STAT_NOTINSTALLED,
170 PKG_STAT_CONFIGFILES,
171 PKG_STAT_HALFINSTALLED,
172 PKG_STAT_UNPACKED,
173 PKG_STAT_HALFCONFIGURED,
174 PKG_STAT_TRIGGERSAWAITED,
175 PKG_STAT_TRIGGERSPENDING,
176 PKG_STAT_INSTALLED,
177};
178
179enum pkgpriority {
180 PKG_PRIO_REQUIRED,
181 PKG_PRIO_IMPORTANT,
182 PKG_PRIO_STANDARD,
183 PKG_PRIO_OPTIONAL,
184 PKG_PRIO_EXTRA,
185 PKG_PRIO_OTHER,
186 PKG_PRIO_UNKNOWN,
187 PKG_PRIO_UNSET = -1,
188};
189
190/**
191 * Node describing an architecture package instance.
192 *
193 * This structure holds state information.
194 */
195struct pkginfo {
196 struct pkgset *set;
197 struct pkginfo *arch_next;
198
199 enum pkgwant want;
200 /** The error flag bitmask. */
201 enum pkgeflag eflag;
202 enum pkgstatus status;
203 enum pkgpriority priority;
204 const char *otherpriority;
205 const char *section;
206 struct dpkg_version configversion;
207 struct filedetails *files;
208 struct pkgbin installed;
209 struct pkgbin available;
210 struct perpackagestate *clientdata;
211
212 struct {
213 /* ->aw == this */
214 struct trigaw *head, *tail;
215 } trigaw;
216
217 /* ->pend == this, non-NULL for us when Triggers-Pending. */
218 struct trigaw *othertrigaw_head;
219 struct trigpend *trigpend_head;
220};
221
222/**
223 * Node describing a package set sharing the same package name.
224 */
225struct pkgset {
226 struct pkgset *next;
227 const char *name;
228 struct pkginfo pkg;
229 struct {
230 struct deppossi *available;
231 struct deppossi *installed;
232 } depended;
233 int installed_instances;
234};
235
236/*** from dbdir.c ***/
237
238const char *dpkg_db_set_dir(const char *dir);
239const char *dpkg_db_get_dir(void);
240char *dpkg_db_get_path(const char *pathpart);
241
242#include <dpkg/atomic-file.h>
243
244/*** from dbmodify.c ***/
245
246enum modstatdb_rw {
247 /* Those marked with \*s*\ are possible returns from modstatdb_init. */
248 msdbrw_readonly/*s*/, msdbrw_needsuperuserlockonly/*s*/,
249 msdbrw_writeifposs,
250 msdbrw_write/*s*/, msdbrw_needsuperuser,
251
252 /* Now some optional flags (starting at bit 8): */
253 msdbrw_available_readonly = DPKG_BIT(8),
254 msdbrw_available_write = DPKG_BIT(9),
255 msdbrw_available_mask = 0xff00,
256};
257
258void modstatdb_init(void);
259void modstatdb_done(void);
260bool modstatdb_is_locked(void);
261bool modstatdb_can_lock(void);
262void modstatdb_lock(void);
263void modstatdb_unlock(void);
264enum modstatdb_rw modstatdb_open(enum modstatdb_rw reqrwflags);
265enum modstatdb_rw modstatdb_get_status(void);
266void modstatdb_note(struct pkginfo *pkg);
267void modstatdb_note_ifwrite(struct pkginfo *pkg);
268void modstatdb_checkpoint(void);
269void modstatdb_shutdown(void);
270
271/*** from database.c ***/
272
273void pkgset_blank(struct pkgset *set);
274int pkgset_installed_instances(struct pkgset *set);
275
276void pkg_blank(struct pkginfo *pp);
277void pkgbin_blank(struct pkgbin *pkgbin);
278bool pkg_is_informative(struct pkginfo *pkg, struct pkgbin *info);
279
280struct pkgset *pkg_db_find_set(const char *name);
281struct pkginfo *pkg_db_get_singleton(struct pkgset *set);
282struct pkginfo *pkg_db_find_singleton(const char *name);
283struct pkginfo *pkg_db_get_pkg(struct pkgset *set, const struct dpkg_arch *arch);
284struct pkginfo *pkg_db_find_pkg(const char *name, const struct dpkg_arch *arch);
285int pkg_db_count_set(void);
286int pkg_db_count_pkg(void);
287void pkg_db_reset(void);
288
289struct pkgiterator *pkg_db_iter_new(void);
290struct pkgset *pkg_db_iter_next_set(struct pkgiterator *iter);
291struct pkginfo *pkg_db_iter_next_pkg(struct pkgiterator *iter);
292void pkg_db_iter_free(struct pkgiterator *iter);
293
294void pkg_db_report(FILE *);
295
296/*** from parse.c ***/
297
298enum parsedbflags {
299 /** Parse a single control stanza. */
300 pdb_single_stanza = DPKG_BIT(0),
301 /** Store in ‘available’ in-core structures, not ‘status’. */
302 pdb_recordavailable = DPKG_BIT(1),
303 /** Throw up an error if ‘Status’ encountered. */
304 pdb_rejectstatus = DPKG_BIT(2),
305 /** Ignore priority/section info if we already have any. */
306 pdb_weakclassification = DPKG_BIT(3),
307 /** Ignore files info if we already have them. */
308 pdb_ignorefiles = DPKG_BIT(4),
309 /** Ignore packages with older versions already read. */
310 pdb_ignoreolder = DPKG_BIT(5),
311 /** Perform laxer version parsing. */
312 pdb_lax_version_parser = DPKG_BIT(6),
313 /** Perform laxer control stanza parsing. */
314 pdb_lax_stanza_parser = DPKG_BIT(9),
315 /** Perform laxer parsing, used to transition to stricter parsing. */
316 pdb_lax_parser = pdb_lax_stanza_parser | pdb_lax_version_parser,
317 /** Close file descriptor on context destruction. */
318 pdb_close_fd = DPKG_BIT(7),
319 /** Interpret filename ‘-’ as stdin. */
320 pdb_dash_is_stdin = DPKG_BIT(8),
321
322 /* Standard operations. */
323
324 pdb_parse_status = pdb_lax_parser | pdb_weakclassification,
325 pdb_parse_update = pdb_parse_status | pdb_single_stanza,
326 pdb_parse_available = pdb_recordavailable | pdb_rejectstatus |
327 pdb_lax_parser,
328 pdb_parse_binary = pdb_recordavailable | pdb_rejectstatus |
329 pdb_single_stanza,
330};
331
332const char *pkg_name_is_illegal(const char *p);
333
334const struct fieldinfo *
335find_field_info(const struct fieldinfo *fields, const char *fieldname);
336const struct arbitraryfield *
337find_arbfield_info(const struct arbitraryfield *arbs, const char *fieldname);
338
339int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep);
340void copy_dependency_links(struct pkginfo *pkg,
341 struct dependency **updateme,
342 struct dependency *newdepends,
343 bool available);
344
345/*** from parsehelp.c ***/
346
347#include <dpkg/namevalue.h>
348
349extern const struct namevalue booleaninfos[];
350extern const struct namevalue multiarchinfos[];
351extern const struct namevalue priorityinfos[];
352extern const struct namevalue statusinfos[];
353extern const struct namevalue eflaginfos[];
354extern const struct namevalue wantinfos[];
355
356#include <dpkg/error.h>
357
358enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always };
359void varbufversion(struct varbuf *, const struct dpkg_version *,
360 enum versiondisplayepochwhen);
361int parseversion(struct dpkg_version *version, const char *,
362 struct dpkg_error *err);
363const char *versiondescribe(const struct dpkg_version *,
364 enum versiondisplayepochwhen);
365
366enum pkg_name_arch_when {
367 /** Never display arch. */
368 pnaw_never,
369 /** Display arch only when it's non-ambiguous. */
370 pnaw_nonambig,
371 /** Display arch only when it's a foreign one. */
372 pnaw_foreign,
373 /** Always display arch. */
374 pnaw_always,
375};
376
377void varbuf_add_pkgbin_name(struct varbuf *vb, const struct pkginfo *pkg,
378 const struct pkgbin *pkgbin,
379 enum pkg_name_arch_when pnaw);
380const char *pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin,
381 enum pkg_name_arch_when pnaw);
382const char *pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw);
383
384void
385pkg_source_version(struct dpkg_version *version,
386 const struct pkginfo *pkg, const struct pkgbin *pkgbin);
387
388void
389varbuf_add_source_version(struct varbuf *vb,
390 const struct pkginfo *pkg, const struct pkgbin *pkgbin);
391
392const char *pkg_want_name(const struct pkginfo *pkg);
393const char *pkg_status_name(const struct pkginfo *pkg);
394const char *pkg_eflag_name(const struct pkginfo *pkg);
395
396const char *pkg_priority_name(const struct pkginfo *pkg);
397
398/*** from dump.c ***/
399
400void writerecord(FILE*, const char*,
401 const struct pkginfo *, const struct pkgbin *);
402
403enum writedb_flags {
404 /** Dump ‘available’ in-core structures, not ‘status’. */
405 wdb_dump_available = DPKG_BIT(0),
406 /** Must sync the written file. */
407 wdb_must_sync = DPKG_BIT(1),
408};
409
410void writedb(const char *filename, enum writedb_flags flags);
411
412/* Note: The varbufs must have been initialized and will not be
413 * NUL-terminated. */
414void varbufrecord(struct varbuf *, const struct pkginfo *,
415 const struct pkgbin *);
416void varbufdependency(struct varbuf *vb, struct dependency *dep);
417
418/*** from depcon.c ***/
419
420bool versionsatisfied(struct pkgbin *it, struct deppossi *against);
421bool deparchsatisfied(struct pkgbin *it, const struct dpkg_arch *arch,
422 struct deppossi *against);
423bool archsatisfied(struct pkgbin *it, struct deppossi *against);
424
425bool
426pkg_virtual_deppossi_satisfied(struct deppossi *dependee,
427 struct deppossi *provider);
428
429/*** from nfmalloc.c ***/
430void *nfmalloc(size_t);
431char *nfstrsave(const char*);
432char *nfstrnsave(const char*, size_t);
433void nffreeall(void);
434
435/** @} */
436
437DPKG_END_DECLS
438
439#endif /* LIBDPKG_DPKG_DB_H */