Commit | Line | Data |
---|---|---|
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 | ||
36 | DPKG_BEGIN_DECLS | |
37 | ||
38 | /** | |
39 | * @defgroup dpkg-db In-core package database management | |
40 | * @ingroup dpkg-public | |
41 | * @{ | |
42 | */ | |
43 | ||
44 | enum 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 | ||
56 | struct dependency { | |
57 | struct pkginfo *up; | |
58 | struct dependency *next; | |
59 | struct deppossi *list; | |
60 | enum deptype type; | |
61 | }; | |
62 | ||
63 | struct 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 | ||
74 | struct arbitraryfield { | |
75 | struct arbitraryfield *next; | |
76 | const char *name; | |
77 | const char *value; | |
78 | }; | |
79 | ||
80 | struct conffile { | |
81 | struct conffile *next; | |
82 | const char *name; | |
83 | const char *hash; | |
84 | bool obsolete; | |
85 | }; | |
86 | ||
87 | struct filedetails { | |
88 | struct filedetails *next; | |
89 | const char *name; | |
90 | const char *msdosname; | |
91 | const char *size; | |
92 | const char *md5sum; | |
93 | }; | |
94 | ||
95 | enum 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 | */ | |
107 | struct 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 | */ | |
134 | struct trigpend { | |
135 | struct trigpend *next; | |
136 | const char *name; | |
137 | }; | |
138 | ||
139 | /** | |
140 | * Node indicates that aw's Triggers-Awaited mentions pend. | |
141 | */ | |
142 | struct 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. */ | |
151 | struct perpackagestate; | |
152 | ||
153 | enum 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 | ||
163 | enum pkgeflag { | |
164 | PKG_EFLAG_OK = 0, | |
165 | PKG_EFLAG_REINSTREQ = 1, | |
166 | }; | |
167 | ||
168 | enum 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 | ||
179 | enum 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 | */ | |
195 | struct 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 | */ | |
225 | struct 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 | ||
238 | const char *dpkg_db_set_dir(const char *dir); | |
239 | const char *dpkg_db_get_dir(void); | |
240 | char *dpkg_db_get_path(const char *pathpart); | |
241 | ||
242 | #include <dpkg/atomic-file.h> | |
243 | ||
244 | /*** from dbmodify.c ***/ | |
245 | ||
246 | enum 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 | ||
258 | void modstatdb_init(void); | |
259 | void modstatdb_done(void); | |
260 | bool modstatdb_is_locked(void); | |
261 | bool modstatdb_can_lock(void); | |
262 | void modstatdb_lock(void); | |
263 | void modstatdb_unlock(void); | |
264 | enum modstatdb_rw modstatdb_open(enum modstatdb_rw reqrwflags); | |
265 | enum modstatdb_rw modstatdb_get_status(void); | |
266 | void modstatdb_note(struct pkginfo *pkg); | |
267 | void modstatdb_note_ifwrite(struct pkginfo *pkg); | |
268 | void modstatdb_checkpoint(void); | |
269 | void modstatdb_shutdown(void); | |
270 | ||
271 | /*** from database.c ***/ | |
272 | ||
273 | void pkgset_blank(struct pkgset *set); | |
274 | int pkgset_installed_instances(struct pkgset *set); | |
275 | ||
276 | void pkg_blank(struct pkginfo *pp); | |
277 | void pkgbin_blank(struct pkgbin *pkgbin); | |
278 | bool pkg_is_informative(struct pkginfo *pkg, struct pkgbin *info); | |
279 | ||
280 | struct pkgset *pkg_db_find_set(const char *name); | |
281 | struct pkginfo *pkg_db_get_singleton(struct pkgset *set); | |
282 | struct pkginfo *pkg_db_find_singleton(const char *name); | |
283 | struct pkginfo *pkg_db_get_pkg(struct pkgset *set, const struct dpkg_arch *arch); | |
284 | struct pkginfo *pkg_db_find_pkg(const char *name, const struct dpkg_arch *arch); | |
285 | int pkg_db_count_set(void); | |
286 | int pkg_db_count_pkg(void); | |
287 | void pkg_db_reset(void); | |
288 | ||
289 | struct pkgiterator *pkg_db_iter_new(void); | |
290 | struct pkgset *pkg_db_iter_next_set(struct pkgiterator *iter); | |
291 | struct pkginfo *pkg_db_iter_next_pkg(struct pkgiterator *iter); | |
292 | void pkg_db_iter_free(struct pkgiterator *iter); | |
293 | ||
294 | void pkg_db_report(FILE *); | |
295 | ||
296 | /*** from parse.c ***/ | |
297 | ||
298 | enum 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 | ||
332 | const char *pkg_name_is_illegal(const char *p); | |
333 | ||
334 | const struct fieldinfo * | |
335 | find_field_info(const struct fieldinfo *fields, const char *fieldname); | |
336 | const struct arbitraryfield * | |
337 | find_arbfield_info(const struct arbitraryfield *arbs, const char *fieldname); | |
338 | ||
339 | int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep); | |
340 | void 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 | ||
349 | extern const struct namevalue booleaninfos[]; | |
350 | extern const struct namevalue multiarchinfos[]; | |
351 | extern const struct namevalue priorityinfos[]; | |
352 | extern const struct namevalue statusinfos[]; | |
353 | extern const struct namevalue eflaginfos[]; | |
354 | extern const struct namevalue wantinfos[]; | |
355 | ||
356 | #include <dpkg/error.h> | |
357 | ||
358 | enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always }; | |
359 | void varbufversion(struct varbuf *, const struct dpkg_version *, | |
360 | enum versiondisplayepochwhen); | |
361 | int parseversion(struct dpkg_version *version, const char *, | |
362 | struct dpkg_error *err); | |
363 | const char *versiondescribe(const struct dpkg_version *, | |
364 | enum versiondisplayepochwhen); | |
365 | ||
366 | enum 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 | ||
377 | void varbuf_add_pkgbin_name(struct varbuf *vb, const struct pkginfo *pkg, | |
378 | const struct pkgbin *pkgbin, | |
379 | enum pkg_name_arch_when pnaw); | |
380 | const char *pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin, | |
381 | enum pkg_name_arch_when pnaw); | |
382 | const char *pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw); | |
383 | ||
384 | void | |
385 | pkg_source_version(struct dpkg_version *version, | |
386 | const struct pkginfo *pkg, const struct pkgbin *pkgbin); | |
387 | ||
388 | void | |
389 | varbuf_add_source_version(struct varbuf *vb, | |
390 | const struct pkginfo *pkg, const struct pkgbin *pkgbin); | |
391 | ||
392 | const char *pkg_want_name(const struct pkginfo *pkg); | |
393 | const char *pkg_status_name(const struct pkginfo *pkg); | |
394 | const char *pkg_eflag_name(const struct pkginfo *pkg); | |
395 | ||
396 | const char *pkg_priority_name(const struct pkginfo *pkg); | |
397 | ||
398 | /*** from dump.c ***/ | |
399 | ||
400 | void writerecord(FILE*, const char*, | |
401 | const struct pkginfo *, const struct pkgbin *); | |
402 | ||
403 | enum 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 | ||
410 | void writedb(const char *filename, enum writedb_flags flags); | |
411 | ||
412 | /* Note: The varbufs must have been initialized and will not be | |
413 | * NUL-terminated. */ | |
414 | void varbufrecord(struct varbuf *, const struct pkginfo *, | |
415 | const struct pkgbin *); | |
416 | void varbufdependency(struct varbuf *vb, struct dependency *dep); | |
417 | ||
418 | /*** from depcon.c ***/ | |
419 | ||
420 | bool versionsatisfied(struct pkgbin *it, struct deppossi *against); | |
421 | bool deparchsatisfied(struct pkgbin *it, const struct dpkg_arch *arch, | |
422 | struct deppossi *against); | |
423 | bool archsatisfied(struct pkgbin *it, struct deppossi *against); | |
424 | ||
425 | bool | |
426 | pkg_virtual_deppossi_satisfied(struct deppossi *dependee, | |
427 | struct deppossi *provider); | |
428 | ||
429 | /*** from nfmalloc.c ***/ | |
430 | void *nfmalloc(size_t); | |
431 | char *nfstrsave(const char*); | |
432 | char *nfstrnsave(const char*, size_t); | |
433 | void nffreeall(void); | |
434 | ||
435 | /** @} */ | |
436 | ||
437 | DPKG_END_DECLS | |
438 | ||
439 | #endif /* LIBDPKG_DPKG_DB_H */ |