dpkg-db.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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-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. #ifndef LIBDPKG_DPKG_DB_H
  23. #define LIBDPKG_DPKG_DB_H
  24. #include <sys/types.h>
  25. #include <stdbool.h>
  26. #include <stdio.h>
  27. #include <dpkg/macros.h>
  28. #include <dpkg/varbuf.h>
  29. #include <dpkg/version.h>
  30. #include <dpkg/arch.h>
  31. DPKG_BEGIN_DECLS
  32. /**
  33. * @defgroup dpkg-db In-core package database management
  34. * @ingroup dpkg-public
  35. * @{
  36. */
  37. enum deptype {
  38. dep_suggests,
  39. dep_recommends,
  40. dep_depends,
  41. dep_predepends,
  42. dep_breaks,
  43. dep_conflicts,
  44. dep_provides,
  45. dep_replaces,
  46. dep_enhances
  47. };
  48. struct dependency {
  49. struct pkginfo *up;
  50. struct dependency *next;
  51. struct deppossi *list;
  52. enum deptype type;
  53. };
  54. struct deppossi {
  55. struct dependency *up;
  56. struct pkgset *ed;
  57. struct deppossi *next, *rev_next, *rev_prev;
  58. const struct dpkg_arch *arch;
  59. struct dpkg_version version;
  60. enum dpkg_relation verrel;
  61. bool arch_is_implicit;
  62. bool cyclebreak;
  63. };
  64. struct arbitraryfield {
  65. struct arbitraryfield *next;
  66. const char *name;
  67. const char *value;
  68. };
  69. struct conffile {
  70. struct conffile *next;
  71. const char *name;
  72. const char *hash;
  73. bool obsolete;
  74. };
  75. struct filedetails {
  76. struct filedetails *next;
  77. const char *name;
  78. const char *msdosname;
  79. const char *size;
  80. const char *md5sum;
  81. };
  82. enum pkgmultiarch {
  83. PKG_MULTIARCH_NO,
  84. PKG_MULTIARCH_SAME,
  85. PKG_MULTIARCH_ALLOWED,
  86. PKG_MULTIARCH_FOREIGN,
  87. };
  88. /**
  89. * Node describing a binary package file.
  90. *
  91. * This structure holds information contained on each binary package.
  92. */
  93. struct pkgbin {
  94. struct dependency *depends;
  95. /** The ‘essential’ flag, true = yes, false = no (absent). */
  96. bool essential;
  97. enum pkgmultiarch multiarch;
  98. const struct dpkg_arch *arch;
  99. /** The following is the "pkgname:archqual" cached string, if this was a
  100. * C++ class this member would be mutable. */
  101. const char *pkgname_archqual;
  102. const char *description;
  103. const char *maintainer;
  104. const char *source;
  105. const char *installedsize;
  106. const char *origin;
  107. const char *bugs;
  108. struct dpkg_version version;
  109. struct conffile *conffiles;
  110. struct arbitraryfield *arbs;
  111. };
  112. /**
  113. * Node indicates that parent's Triggers-Pending mentions name.
  114. *
  115. * Note: These nodes do double duty: after they're removed from a package's
  116. * trigpend list, references may be preserved by the trigger cycle checker
  117. * (see trigproc.c).
  118. */
  119. struct trigpend {
  120. struct trigpend *next;
  121. const char *name;
  122. };
  123. /**
  124. * Node indicates that aw's Triggers-Awaited mentions pend.
  125. */
  126. struct trigaw {
  127. struct pkginfo *aw, *pend;
  128. struct trigaw *samepend_next;
  129. struct {
  130. struct trigaw *next, *prev;
  131. } sameaw;
  132. };
  133. /* Note: dselect and dpkg have different versions of this. */
  134. struct perpackagestate;
  135. enum pkgwant {
  136. want_unknown,
  137. want_install,
  138. want_hold,
  139. want_deinstall,
  140. want_purge,
  141. /** Not allowed except as special sentinel value in some places. */
  142. want_sentinel,
  143. };
  144. enum pkgeflag {
  145. eflag_ok = 0,
  146. eflag_reinstreq = 1,
  147. };
  148. enum pkgstatus {
  149. stat_notinstalled,
  150. stat_configfiles,
  151. stat_halfinstalled,
  152. stat_unpacked,
  153. stat_halfconfigured,
  154. stat_triggersawaited,
  155. stat_triggerspending,
  156. stat_installed,
  157. };
  158. enum pkgpriority {
  159. pri_required,
  160. pri_important,
  161. pri_standard,
  162. pri_optional,
  163. pri_extra,
  164. pri_other,
  165. pri_unknown,
  166. pri_unset = -1,
  167. };
  168. /**
  169. * Node describing an architecture package instance.
  170. *
  171. * This structure holds state information.
  172. */
  173. struct pkginfo {
  174. struct pkgset *set;
  175. struct pkginfo *arch_next;
  176. enum pkgwant want;
  177. /** The error flag bitmask. */
  178. enum pkgeflag eflag;
  179. enum pkgstatus status;
  180. enum pkgpriority priority;
  181. const char *otherpriority;
  182. const char *section;
  183. struct dpkg_version configversion;
  184. struct filedetails *files;
  185. struct pkgbin installed;
  186. struct pkgbin available;
  187. struct perpackagestate *clientdata;
  188. struct {
  189. /* ->aw == this */
  190. struct trigaw *head, *tail;
  191. } trigaw;
  192. /* ->pend == this, non-NULL for us when Triggers-Pending. */
  193. struct trigaw *othertrigaw_head;
  194. struct trigpend *trigpend_head;
  195. };
  196. /**
  197. * Node describing a package set sharing the same package name.
  198. */
  199. struct pkgset {
  200. struct pkgset *next;
  201. const char *name;
  202. struct pkginfo pkg;
  203. struct {
  204. struct deppossi *available;
  205. struct deppossi *installed;
  206. } depended;
  207. int installed_instances;
  208. };
  209. /*** from dbdir.c ***/
  210. const char *dpkg_db_set_dir(const char *dir);
  211. const char *dpkg_db_get_dir(void);
  212. char *dpkg_db_get_path(const char *pathpart);
  213. #include <dpkg/atomic-file.h>
  214. /*** from dbmodify.c ***/
  215. enum modstatdb_rw {
  216. /* Those marked with \*s*\ are possible returns from modstatdb_init. */
  217. msdbrw_readonly/*s*/, msdbrw_needsuperuserlockonly/*s*/,
  218. msdbrw_writeifposs,
  219. msdbrw_write/*s*/, msdbrw_needsuperuser,
  220. /* Now some optional flags (starting at bit 8): */
  221. msdbrw_available_readonly = DPKG_BIT(8),
  222. msdbrw_available_write = DPKG_BIT(9),
  223. msdbrw_available_mask = 0xff00,
  224. };
  225. void modstatdb_init(void);
  226. void modstatdb_done(void);
  227. bool modstatdb_is_locked(void);
  228. bool modstatdb_can_lock(void);
  229. void modstatdb_lock(void);
  230. void modstatdb_unlock(void);
  231. enum modstatdb_rw modstatdb_open(enum modstatdb_rw reqrwflags);
  232. enum modstatdb_rw modstatdb_get_status(void);
  233. void modstatdb_note(struct pkginfo *pkg);
  234. void modstatdb_note_ifwrite(struct pkginfo *pkg);
  235. void modstatdb_checkpoint(void);
  236. void modstatdb_shutdown(void);
  237. /*** from database.c ***/
  238. void pkgset_blank(struct pkgset *set);
  239. int pkgset_installed_instances(struct pkgset *set);
  240. void pkg_blank(struct pkginfo *pp);
  241. void pkgbin_blank(struct pkgbin *pkgbin);
  242. bool pkg_is_informative(struct pkginfo *pkg, struct pkgbin *info);
  243. struct pkgset *pkg_db_find_set(const char *name);
  244. struct pkginfo *pkg_db_get_singleton(struct pkgset *set);
  245. struct pkginfo *pkg_db_find_singleton(const char *name);
  246. struct pkginfo *pkg_db_get_pkg(struct pkgset *set, const struct dpkg_arch *arch);
  247. struct pkginfo *pkg_db_find_pkg(const char *name, const struct dpkg_arch *arch);
  248. int pkg_db_count_set(void);
  249. int pkg_db_count_pkg(void);
  250. void pkg_db_reset(void);
  251. struct pkgiterator *pkg_db_iter_new(void);
  252. struct pkgset *pkg_db_iter_next_set(struct pkgiterator *iter);
  253. struct pkginfo *pkg_db_iter_next_pkg(struct pkgiterator *iter);
  254. void pkg_db_iter_free(struct pkgiterator *iter);
  255. void pkg_db_report(FILE *);
  256. /*** from parse.c ***/
  257. enum parsedbflags {
  258. /** Parse a single control stanza. */
  259. pdb_single_stanza = DPKG_BIT(0),
  260. /** Store in ‘available’ in-core structures, not ‘status’. */
  261. pdb_recordavailable = DPKG_BIT(1),
  262. /** Throw up an error if ‘Status’ encountered. */
  263. pdb_rejectstatus = DPKG_BIT(2),
  264. /** Ignore priority/section info if we already have any. */
  265. pdb_weakclassification = DPKG_BIT(3),
  266. /** Ignore files info if we already have them. */
  267. pdb_ignorefiles = DPKG_BIT(4),
  268. /** Ignore packages with older versions already read. */
  269. pdb_ignoreolder = DPKG_BIT(5),
  270. /** Perform laxer version parsing. */
  271. pdb_lax_version_parser = DPKG_BIT(6),
  272. /** Perform laxer parsing, used to transition to stricter parsing. */
  273. pdb_lax_parser = pdb_lax_version_parser,
  274. /** Close file descriptor on context destruction. */
  275. pdb_close_fd = DPKG_BIT(7),
  276. /** Interpret filename ‘-’ as stdin. */
  277. pdb_dash_is_stdin = DPKG_BIT(8),
  278. /* Standard operations. */
  279. pdb_parse_status = pdb_lax_parser | pdb_weakclassification,
  280. pdb_parse_update = pdb_parse_status | pdb_single_stanza,
  281. pdb_parse_available = pdb_recordavailable | pdb_rejectstatus |
  282. pdb_lax_parser,
  283. pdb_parse_binary = pdb_recordavailable | pdb_rejectstatus |
  284. pdb_single_stanza,
  285. };
  286. const char *pkg_name_is_illegal(const char *p);
  287. int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep);
  288. void copy_dependency_links(struct pkginfo *pkg,
  289. struct dependency **updateme,
  290. struct dependency *newdepends,
  291. bool available);
  292. /*** from parsehelp.c ***/
  293. #include <dpkg/namevalue.h>
  294. extern const struct namevalue booleaninfos[];
  295. extern const struct namevalue multiarchinfos[];
  296. extern const struct namevalue priorityinfos[];
  297. extern const struct namevalue statusinfos[];
  298. extern const struct namevalue eflaginfos[];
  299. extern const struct namevalue wantinfos[];
  300. #include <dpkg/error.h>
  301. enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always };
  302. void varbufversion(struct varbuf *, const struct dpkg_version *,
  303. enum versiondisplayepochwhen);
  304. int parseversion(struct dpkg_version *version, const char *,
  305. struct dpkg_error *err);
  306. const char *versiondescribe(const struct dpkg_version *,
  307. enum versiondisplayepochwhen);
  308. enum pkg_name_arch_when {
  309. /** Never display arch. */
  310. pnaw_never,
  311. /** Display arch only when it's non-ambiguous. */
  312. pnaw_nonambig,
  313. /** Display arch only when it's a foreign one. */
  314. pnaw_foreign,
  315. /** Always display arch. */
  316. pnaw_always,
  317. };
  318. void varbuf_add_pkgbin_name(struct varbuf *vb, const struct pkginfo *pkg,
  319. const struct pkgbin *pkgbin,
  320. enum pkg_name_arch_when pnaw);
  321. const char *pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin,
  322. enum pkg_name_arch_when pnaw);
  323. const char *pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw);
  324. const char *pkg_want_name(const struct pkginfo *pkg);
  325. const char *pkg_status_name(const struct pkginfo *pkg);
  326. const char *pkg_eflag_name(const struct pkginfo *pkg);
  327. const char *pkg_priority_name(const struct pkginfo *pkg);
  328. /*** from dump.c ***/
  329. void writerecord(FILE*, const char*,
  330. const struct pkginfo *, const struct pkgbin *);
  331. enum writedb_flags {
  332. /** Dump ‘available’ in-core structures, not ‘status’. */
  333. wdb_dump_available = DPKG_BIT(0),
  334. /** Must sync the written file. */
  335. wdb_must_sync = DPKG_BIT(1),
  336. };
  337. void writedb(const char *filename, enum writedb_flags flags);
  338. /* Note: The varbufs must have been initialized and will not be
  339. * NUL-terminated. */
  340. void varbufrecord(struct varbuf *, const struct pkginfo *,
  341. const struct pkgbin *);
  342. void varbufdependency(struct varbuf *vb, struct dependency *dep);
  343. /*** from depcon.c ***/
  344. bool versionsatisfied(struct pkgbin *it, struct deppossi *against);
  345. bool deparchsatisfied(struct pkgbin *it, const struct dpkg_arch *arch,
  346. struct deppossi *against);
  347. bool archsatisfied(struct pkgbin *it, struct deppossi *against);
  348. /*** from nfmalloc.c ***/
  349. void *nfmalloc(size_t);
  350. char *nfstrsave(const char*);
  351. char *nfstrnsave(const char*, size_t);
  352. void nffreeall(void);
  353. /** @} */
  354. DPKG_END_DECLS
  355. #endif /* LIBDPKG_DPKG_DB_H */