dpkg-db.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * dpkg-db.h - declarations for in-core package database management
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright (C) 2000,2001 Wichert Akkerman
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with dpkg; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #ifndef DPKG_DB_H
  23. #define DPKG_DB_H
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. struct versionrevision {
  28. unsigned long epoch;
  29. const char *version;
  30. const char *revision;
  31. };
  32. enum deptype {
  33. dep_suggests,
  34. dep_recommends,
  35. dep_depends,
  36. dep_predepends,
  37. dep_conflicts,
  38. dep_provides,
  39. dep_replaces,
  40. dep_enhances
  41. };
  42. enum depverrel {
  43. dvrf_earlier= 0001,
  44. dvrf_later= 0002,
  45. dvrf_strict= 0010,
  46. dvrf_orequal= 0020,
  47. dvrf_builtup= 0100,
  48. dvr_none= 0200,
  49. dvr_earlierequal= dvrf_builtup | dvrf_earlier | dvrf_orequal,
  50. dvr_earlierstrict= dvrf_builtup | dvrf_earlier | dvrf_strict,
  51. dvr_laterequal= dvrf_builtup | dvrf_later | dvrf_orequal,
  52. dvr_laterstrict= dvrf_builtup | dvrf_later | dvrf_strict,
  53. dvr_exact= 0400
  54. };
  55. struct dependency {
  56. struct pkginfo *up;
  57. struct dependency *next;
  58. struct deppossi *list;
  59. enum deptype type;
  60. };
  61. struct deppossi {
  62. struct dependency *up;
  63. struct pkginfo *ed;
  64. struct deppossi *next, *nextrev, *backrev;
  65. struct versionrevision version;
  66. enum depverrel verrel;
  67. int cyclebreak;
  68. };
  69. struct arbitraryfield {
  70. struct arbitraryfield *next;
  71. char *name;
  72. char *value;
  73. };
  74. struct conffile {
  75. struct conffile *next;
  76. const char *name;
  77. const char *hash;
  78. };
  79. struct filedetails {
  80. struct filedetails *next;
  81. char *name;
  82. char *msdosname;
  83. char *size;
  84. char *md5sum;
  85. };
  86. struct pkginfoperfile { /* pif */
  87. int valid;
  88. struct dependency *depends;
  89. struct deppossi *depended;
  90. int essential; /* The `essential' flag, 1=yes, 0=no (absent) */
  91. char *description, *maintainer, *source, *architecture, *installedsize, *origin, *bugs;
  92. struct versionrevision version;
  93. struct conffile *conffiles;
  94. struct arbitraryfield *arbs;
  95. };
  96. struct perpackagestate; /* dselect and dpkg have different versions of this */
  97. struct pkginfo { /* pig */
  98. struct pkginfo *next;
  99. const char *name;
  100. enum pkgwant {
  101. want_unknown, want_install, want_hold, want_deinstall, want_purge,
  102. want_sentinel /* Not allowed except as special sentinel value
  103. in some places */
  104. } want;
  105. enum pkgeflag {
  106. eflagf_reinstreq = 01,
  107. eflagf_obsoletehold = 02,
  108. eflagv_ok = 0,
  109. eflagv_reinstreq = eflagf_reinstreq,
  110. eflagv_obsoletehold = eflagf_obsoletehold,
  111. eflagv_obsoleteboth = eflagf_reinstreq | eflagf_obsoletehold
  112. } eflag; /* bitmask, but obsoletehold no longer used except when reading */
  113. enum pkgstatus {
  114. stat_notinstalled, stat_unpacked, stat_halfconfigured,
  115. stat_installed, stat_halfinstalled, stat_configfiles
  116. } status;
  117. enum pkgpriority {
  118. pri_required, pri_important, pri_standard, pri_recommended,
  119. pri_optional, pri_extra, pri_contrib,
  120. pri_other, pri_unknown, pri_unset=-1
  121. } priority;
  122. const char *otherpriority;
  123. const char *section;
  124. struct versionrevision configversion;
  125. struct filedetails *files;
  126. struct pkginfoperfile installed;
  127. struct pkginfoperfile available;
  128. struct perpackagestate *clientdata;
  129. enum { white, gray, black } color; /* used during cycle detection */
  130. };
  131. /*** from lock.c ***/
  132. void lockdatabase(const char *admindir);
  133. void unlockdatabase(const char *admindir);
  134. /*** from dbmodify.c ***/
  135. enum modstatdb_rw {
  136. /* Those marked with \*s*\ are possible returns from modstatdb_init. */
  137. msdbrw_readonly/*s*/, msdbrw_needsuperuserlockonly/*s*/,
  138. msdbrw_writeifposs,
  139. msdbrw_write/*s*/, msdbrw_needsuperuser,
  140. /* Now some optional flags: */
  141. msdbrw_flagsmask= ~077,
  142. /* flags start at 0100 */
  143. msdbrw_noavail= 0100,
  144. };
  145. struct pipef {
  146. int fd;
  147. struct pipef *next;
  148. };
  149. extern struct pipef *status_pipes;
  150. enum modstatdb_rw modstatdb_init(const char *admindir, enum modstatdb_rw reqrwflags);
  151. void modstatdb_note(struct pkginfo *pkg);
  152. void modstatdb_shutdown(void);
  153. extern char *statusfile, *availablefile; /* initialised by modstatdb_init */
  154. /*** from database.c ***/
  155. struct pkginfo *findpackage(const char *name);
  156. void blankpackage(struct pkginfo *pp);
  157. void blankpackageperfile(struct pkginfoperfile *pifp);
  158. void blankversion(struct versionrevision*);
  159. int informative(struct pkginfo *pkg, struct pkginfoperfile *info);
  160. int countpackages(void);
  161. void resetpackages(void);
  162. struct pkgiterator *iterpkgstart(void);
  163. struct pkginfo *iterpkgnext(struct pkgiterator*);
  164. void iterpkgend(struct pkgiterator*);
  165. void hashreport(FILE*);
  166. /*** from parse.c ***/
  167. enum parsedbflags {
  168. pdb_recordavailable =001, /* Store in `available' in-core structures, not `status' */
  169. pdb_rejectstatus =002, /* Throw up an error if `Status' encountered */
  170. pdb_weakclassification=004, /* Ignore priority/section info if we already have any */
  171. pdb_ignorefiles =010 /* Ignore files info if we already have them */
  172. };
  173. const char *illegal_packagename(const char *p, const char **ep);
  174. int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep,
  175. FILE *warnto, int *warncount);
  176. void copy_dependency_links(struct pkginfo *pkg,
  177. struct dependency **updateme,
  178. struct dependency *newdepends,
  179. int available);
  180. /*** from parsehelp.c ***/
  181. struct namevalue {
  182. const char *name;
  183. int value, length;
  184. };
  185. extern const struct namevalue booleaninfos[];
  186. extern const struct namevalue priorityinfos[];
  187. extern const struct namevalue statusinfos[];
  188. extern const struct namevalue eflaginfos[];
  189. extern const struct namevalue wantinfos[];
  190. const char *skip_slash_dotslash(const char *p);
  191. int informativeversion(const struct versionrevision *version);
  192. enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always };
  193. void varbufversion(struct varbuf*, const struct versionrevision*,
  194. enum versiondisplayepochwhen);
  195. const char *parseversion(struct versionrevision *rversion, const char*);
  196. const char *versiondescribe(const struct versionrevision*,
  197. enum versiondisplayepochwhen);
  198. /*** from varbuf.c ***/
  199. struct varbuf;
  200. extern void varbufaddc(struct varbuf *v, int c);
  201. extern void varbufdupc(struct varbuf *v, int c, ssize_t s);
  202. int varbufprintf(struct varbuf *v, const char *fmt, ...) PRINTFFORMAT(2,3);
  203. int varbufvprintf(struct varbuf *v, const char *fmt, va_list va);
  204. void varbufinit(struct varbuf *v);
  205. void varbufreset(struct varbuf *v);
  206. void varbufextend(struct varbuf *v);
  207. void varbuffree(struct varbuf *v);
  208. #define varbufaddstr(v, s) varbufaddbuf(v, s, strlen(s))
  209. extern void varbufaddbuf(struct varbuf *v, const void *s, const int l);
  210. /* varbufinit must be called exactly once before the use of each varbuf
  211. * (including before any call to varbuffree).
  212. *
  213. * However, varbufs allocated `static' are properly initialised anyway and
  214. * do not need varbufinit; multiple consecutive calls to varbufinit before
  215. * any use are allowed.
  216. *
  217. * varbuffree must be called after a varbuf is finished with, if anything
  218. * other than varbufinit has been done. After this you are allowed but
  219. * not required to call varbufinit again if you want to start using the
  220. * varbuf again.
  221. *
  222. * Callers using C++ need not worry about any of this.
  223. */
  224. struct varbuf {
  225. size_t used, size;
  226. char *buf;
  227. #ifdef __cplusplus
  228. void init() { varbufinit(this); }
  229. void free() { varbuffree(this); }
  230. varbuf() { varbufinit(this); }
  231. ~varbuf() { varbuffree(this); }
  232. void operator()(int c) { varbufaddc(this,c); }
  233. void operator()(const char *s) { varbufaddstr(this,s); }
  234. void terminate(void/*to shut 2.6.3 up*/) { varbufaddc(this,0); used--; }
  235. void reset() { used=0; }
  236. const char *string() { terminate(); return buf; }
  237. #endif
  238. };
  239. /*** from dump.c ***/
  240. void writerecord(FILE*, const char*,
  241. const struct pkginfo*, const struct pkginfoperfile*);
  242. void writedb(const char *filename, int available, int mustsync);
  243. void varbufrecord(struct varbuf*, const struct pkginfo*, const struct pkginfoperfile*);
  244. void varbufdependency(struct varbuf *vb, struct dependency *dep);
  245. /* NB THE VARBUF MUST HAVE BEEN INITIALISED AND WILL NOT BE NULL-TERMINATED */
  246. /*** from vercmp.c ***/
  247. int versionsatisfied(struct pkginfoperfile *it, struct deppossi *against);
  248. int versionsatisfied3(const struct versionrevision *it,
  249. const struct versionrevision *ref,
  250. enum depverrel verrel);
  251. int versioncompare(const struct versionrevision *version,
  252. const struct versionrevision *refversion);
  253. int epochsdiffer(const struct versionrevision *a,
  254. const struct versionrevision *b);
  255. /*** from nfmalloc.c ***/
  256. extern void *nfmalloc(size_t);
  257. char *nfstrsave(const char*);
  258. char *nfstrnsave(const char*, int);
  259. void nffreeall(void);
  260. /*** from showpkg.c ***/
  261. struct lstitem;
  262. struct lstitem* parseformat(const char* fmt);
  263. void freeformat(struct lstitem* head);
  264. void show1package(const struct lstitem* head, struct pkginfo *pkg);
  265. #endif /* DPKG_DB_H */