Imported Upstream version 1.16.10
[services/dpkg.git] / lib / dpkg / dpkg-db.h
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 <ian@chiark.greenend.org.uk>
6  * Copyright © 2000,2001 Wichert Akkerman
7  * Copyright © 2006-2012 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 <http://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 /**
96  * Node describing a binary package file.
97  *
98  * This structure holds information contained on each binary package.
99  */
100 struct pkgbin {
101   struct dependency *depends;
102   /** The ‘essential’ flag, true = yes, false = no (absent). */
103   bool essential;
104   enum pkgmultiarch {
105     multiarch_no,
106     multiarch_same,
107     multiarch_allowed,
108     multiarch_foreign,
109   } multiarch;
110   const struct dpkg_arch *arch;
111   /** The following is the "pkgname:archqual" cached string, if this was a
112    * C++ class this member would be mutable. */
113   const char *pkgname_archqual;
114   const char *description;
115   const char *maintainer;
116   const char *source;
117   const char *installedsize;
118   const char *origin;
119   const char *bugs;
120   struct dpkg_version version;
121   struct conffile *conffiles;
122   struct arbitraryfield *arbs;
123 };
124
125 /**
126  * Node indicates that parent's Triggers-Pending mentions name.
127  *
128  * Note: These nodes do double duty: after they're removed from a package's
129  * trigpend list, references may be preserved by the trigger cycle checker
130  * (see trigproc.c).
131  */
132 struct trigpend {
133   struct trigpend *next;
134   const char *name;
135 };
136
137 /**
138  * Node indicates that aw's Triggers-Awaited mentions pend.
139  */
140 struct trigaw {
141   struct pkginfo *aw, *pend;
142   struct trigaw *samepend_next;
143   struct {
144     struct trigaw *next, *prev;
145   } sameaw;
146 };
147
148 /* Note: dselect and dpkg have different versions of this. */
149 struct perpackagestate;
150
151 /**
152  * Node describing an architecture package instance.
153  *
154  * This structure holds state information.
155  */
156 struct pkginfo {
157   struct pkgset *set;
158   struct pkginfo *arch_next;
159
160   enum pkgwant {
161     want_unknown, want_install, want_hold, want_deinstall, want_purge,
162     /** Not allowed except as special sentinel value in some places. */
163     want_sentinel,
164   } want;
165   /** The error flag bitmask. */
166   enum pkgeflag {
167     eflag_ok            = 0,
168     eflag_reinstreq     = 1,
169   } eflag;
170   enum pkgstatus {
171     stat_notinstalled,
172     stat_configfiles,
173     stat_halfinstalled,
174     stat_unpacked,
175     stat_halfconfigured,
176     stat_triggersawaited,
177     stat_triggerspending,
178     stat_installed
179   } status;
180   enum pkgpriority {
181     pri_required,
182     pri_important,
183     pri_standard,
184     pri_optional,
185     pri_extra,
186     pri_other, pri_unknown, pri_unset=-1
187   } priority;
188   const char *otherpriority;
189   const char *section;
190   struct dpkg_version configversion;
191   struct filedetails *files;
192   struct pkgbin installed;
193   struct pkgbin available;
194   struct perpackagestate *clientdata;
195
196   struct {
197     /* ->aw == this */
198     struct trigaw *head, *tail;
199   } trigaw;
200
201   /* ->pend == this, non-NULL for us when Triggers-Pending. */
202   struct trigaw *othertrigaw_head;
203   struct trigpend *trigpend_head;
204 };
205
206 /**
207  * Node describing a package set sharing the same package name.
208  */
209 struct pkgset {
210   struct pkgset *next;
211   const char *name;
212   struct pkginfo pkg;
213   struct {
214     struct deppossi *available;
215     struct deppossi *installed;
216   } depended;
217   int installed_instances;
218 };
219
220 /*** from dbdir.c ***/
221
222 const char *dpkg_db_set_dir(const char *dir);
223 const char *dpkg_db_get_dir(void);
224 char *dpkg_db_get_path(const char *pathpart);
225
226 #include <dpkg/atomic-file.h>
227
228 /*** from dbmodify.c ***/
229
230 enum modstatdb_rw {
231   /* Those marked with \*s*\ are possible returns from modstatdb_init. */
232   msdbrw_readonly/*s*/, msdbrw_needsuperuserlockonly/*s*/,
233   msdbrw_writeifposs,
234   msdbrw_write/*s*/, msdbrw_needsuperuser,
235
236   /* Now some optional flags (starting at bit 8): */
237   msdbrw_available_readonly     = DPKG_BIT(8),
238   msdbrw_available_write        = DPKG_BIT(9),
239   msdbrw_available_mask         = 0xff00,
240 };
241
242 void modstatdb_init(void);
243 void modstatdb_done(void);
244 bool modstatdb_is_locked(void);
245 bool modstatdb_can_lock(void);
246 void modstatdb_lock(void);
247 void modstatdb_unlock(void);
248 enum modstatdb_rw modstatdb_open(enum modstatdb_rw reqrwflags);
249 enum modstatdb_rw modstatdb_get_status(void);
250 void modstatdb_note(struct pkginfo *pkg);
251 void modstatdb_note_ifwrite(struct pkginfo *pkg);
252 void modstatdb_checkpoint(void);
253 void modstatdb_shutdown(void);
254
255 /*** from database.c ***/
256
257 void pkgset_blank(struct pkgset *set);
258 int pkgset_installed_instances(struct pkgset *set);
259
260 void pkg_blank(struct pkginfo *pp);
261 void pkgbin_blank(struct pkgbin *pkgbin);
262 bool pkg_is_informative(struct pkginfo *pkg, struct pkgbin *info);
263
264 struct pkgset *pkg_db_find_set(const char *name);
265 struct pkginfo *pkg_db_get_singleton(struct pkgset *set);
266 struct pkginfo *pkg_db_find_singleton(const char *name);
267 struct pkginfo *pkg_db_get_pkg(struct pkgset *set, const struct dpkg_arch *arch);
268 struct pkginfo *pkg_db_find_pkg(const char *name, const struct dpkg_arch *arch);
269 int pkg_db_count_set(void);
270 int pkg_db_count_pkg(void);
271 void pkg_db_reset(void);
272
273 struct pkgiterator *pkg_db_iter_new(void);
274 struct pkgset *pkg_db_iter_next_set(struct pkgiterator *iter);
275 struct pkginfo *pkg_db_iter_next_pkg(struct pkgiterator *iter);
276 void pkg_db_iter_free(struct pkgiterator *iter);
277
278 void pkg_db_report(FILE *);
279
280 /*** from parse.c ***/
281
282 enum parsedbflags {
283   /** Parse the control file from a binary .deb package. */
284   pdb_deb_control               = DPKG_BIT(0),
285   /** Store in ‘available’ in-core structures, not ‘status’. */
286   pdb_recordavailable           = DPKG_BIT(1),
287   /** Throw up an error if ‘Status’ encountered. */
288   pdb_rejectstatus              = DPKG_BIT(2),
289   /** Ignore priority/section info if we already have any. */
290   pdb_weakclassification        = DPKG_BIT(3),
291   /** Ignore files info if we already have them. */
292   pdb_ignorefiles               = DPKG_BIT(4),
293   /** Ignore packages with older versions already read. */
294   pdb_ignoreolder               = DPKG_BIT(5),
295   /** Perform laxer version parsing. */
296   pdb_lax_version_parser        = DPKG_BIT(6),
297   /** Perform laxer parsing, used to transition to stricter parsing. */
298   pdb_lax_parser                = pdb_lax_version_parser,
299
300   /* Standard operations. */
301
302   pdb_parse_status              = pdb_lax_parser | pdb_weakclassification,
303   pdb_parse_update              = pdb_parse_status | pdb_deb_control,
304   pdb_parse_available           = pdb_recordavailable | pdb_rejectstatus |
305                                   pdb_lax_parser,
306   pdb_parse_binary              = pdb_recordavailable | pdb_rejectstatus |
307                                   pdb_deb_control,
308 };
309
310 const char *pkg_name_is_illegal(const char *p);
311 int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep);
312 void copy_dependency_links(struct pkginfo *pkg,
313                            struct dependency **updateme,
314                            struct dependency *newdepends,
315                            bool available);
316
317 /*** from parsehelp.c ***/
318
319 #include <dpkg/namevalue.h>
320
321 extern const struct namevalue booleaninfos[];
322 extern const struct namevalue multiarchinfos[];
323 extern const struct namevalue priorityinfos[];
324 extern const struct namevalue statusinfos[];
325 extern const struct namevalue eflaginfos[];
326 extern const struct namevalue wantinfos[];
327
328 #include <dpkg/error.h>
329
330 enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always };
331 void varbufversion(struct varbuf *, const struct dpkg_version *,
332                    enum versiondisplayepochwhen);
333 int parseversion(struct dpkg_version *version, const char *,
334                  struct dpkg_error *err);
335 const char *versiondescribe(const struct dpkg_version *,
336                             enum versiondisplayepochwhen);
337
338 enum pkg_name_arch_when {
339   /** Never display arch. */
340   pnaw_never,
341   /** Display arch only when it's non-ambiguous. */
342   pnaw_nonambig,
343   /** Display arch only when it's a foreign one. */
344   pnaw_foreign,
345   /** Always display arch. */
346   pnaw_always,
347 };
348
349 void varbuf_add_pkgbin_name(struct varbuf *vb, const struct pkginfo *pkg,
350                             const struct pkgbin *pkgbin,
351                             enum pkg_name_arch_when pnaw);
352 const char *pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin,
353                         enum pkg_name_arch_when pnaw);
354 const char *pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw);
355
356 /*** from dump.c ***/
357
358 void writerecord(FILE*, const char*,
359                  const struct pkginfo *, const struct pkgbin *);
360
361 enum writedb_flags {
362   /** Dump ‘available’ in-core structures, not ‘status’. */
363   wdb_dump_available            = DPKG_BIT(0),
364   /** Must sync the written file. */
365   wdb_must_sync                 = DPKG_BIT(1),
366 };
367
368 void writedb(const char *filename, enum writedb_flags flags);
369
370 /* Note: The varbufs must have been initialized and will not be
371  * NUL-terminated. */
372 void varbufrecord(struct varbuf *, const struct pkginfo *,
373                   const struct pkgbin *);
374 void varbufdependency(struct varbuf *vb, struct dependency *dep);
375
376 /*** from depcon.c ***/
377
378 bool versionsatisfied(struct pkgbin *it, struct deppossi *against);
379 bool deparchsatisfied(struct pkgbin *it, const struct dpkg_arch *arch,
380                       struct deppossi *against);
381 bool archsatisfied(struct pkgbin *it, struct deppossi *against);
382
383 /*** from nfmalloc.c ***/
384 void *nfmalloc(size_t);
385 char *nfstrsave(const char*);
386 char *nfstrnsave(const char*, size_t);
387 void nffreeall(void);
388
389 /** @} */
390
391 DPKG_END_DECLS
392
393 #endif /* LIBDPKG_DPKG_DB_H */