dpkg-db.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. int obsolete;
  79. };
  80. struct filedetails {
  81. struct filedetails *next;
  82. char *name;
  83. char *msdosname;
  84. char *size;
  85. char *md5sum;
  86. };
  87. struct pkginfoperfile { /* pif */
  88. int valid;
  89. struct dependency *depends;
  90. struct deppossi *depended;
  91. int essential; /* The `essential' flag, 1=yes, 0=no (absent) */
  92. char *description, *maintainer, *source, *architecture, *installedsize, *origin, *bugs;
  93. struct versionrevision version;
  94. struct conffile *conffiles;
  95. struct arbitraryfield *arbs;
  96. };
  97. struct perpackagestate; /* dselect and dpkg have different versions of this */
  98. struct pkginfo { /* pig */
  99. struct pkginfo *next;
  100. const char *name;
  101. enum pkgwant {
  102. want_unknown, want_install, want_hold, want_deinstall, want_purge,
  103. want_sentinel /* Not allowed except as special sentinel value
  104. in some places */
  105. } want;
  106. enum pkgeflag {
  107. eflagf_reinstreq = 01,
  108. eflagf_obsoletehold = 02,
  109. eflagv_ok = 0,
  110. eflagv_reinstreq = eflagf_reinstreq,
  111. eflagv_obsoletehold = eflagf_obsoletehold,
  112. eflagv_obsoleteboth = eflagf_reinstreq | eflagf_obsoletehold
  113. } eflag; /* bitmask, but obsoletehold no longer used except when reading */
  114. enum pkgstatus {
  115. stat_notinstalled, stat_unpacked, stat_halfconfigured,
  116. stat_installed, stat_halfinstalled, stat_configfiles
  117. } status;
  118. enum pkgpriority {
  119. pri_required, pri_important, pri_standard, pri_recommended,
  120. pri_optional, pri_extra, pri_contrib,
  121. pri_other, pri_unknown, pri_unset=-1
  122. } priority;
  123. const char *otherpriority;
  124. const char *section;
  125. struct versionrevision configversion;
  126. struct filedetails *files;
  127. struct pkginfoperfile installed;
  128. struct pkginfoperfile available;
  129. struct perpackagestate *clientdata;
  130. enum { white, gray, black } color; /* used during cycle detection */
  131. };
  132. /*** from lock.c ***/
  133. void lockdatabase(const char *admindir);
  134. void unlockdatabase(const char *admindir);
  135. /*** from dbmodify.c ***/
  136. enum modstatdb_rw {
  137. /* Those marked with \*s*\ are possible returns from modstatdb_init. */
  138. msdbrw_readonly/*s*/, msdbrw_needsuperuserlockonly/*s*/,
  139. msdbrw_writeifposs,
  140. msdbrw_write/*s*/, msdbrw_needsuperuser,
  141. /* Now some optional flags: */
  142. msdbrw_flagsmask= ~077,
  143. /* flags start at 0100 */
  144. msdbrw_noavail= 0100,
  145. };
  146. struct pipef {
  147. int fd;
  148. struct pipef *next;
  149. };
  150. extern struct pipef *status_pipes;
  151. enum modstatdb_rw modstatdb_init(const char *admindir, enum modstatdb_rw reqrwflags);
  152. void modstatdb_note(struct pkginfo *pkg);
  153. void modstatdb_shutdown(void);
  154. extern char *statusfile, *availablefile; /* initialised by modstatdb_init */
  155. void log_message(const char *fmt, ...);
  156. /*** from database.c ***/
  157. struct pkginfo *findpackage(const char *name);
  158. void blankpackage(struct pkginfo *pp);
  159. void blankpackageperfile(struct pkginfoperfile *pifp);
  160. void blankversion(struct versionrevision*);
  161. int informative(struct pkginfo *pkg, struct pkginfoperfile *info);
  162. int countpackages(void);
  163. void resetpackages(void);
  164. struct pkgiterator *iterpkgstart(void);
  165. struct pkginfo *iterpkgnext(struct pkgiterator*);
  166. void iterpkgend(struct pkgiterator*);
  167. void hashreport(FILE*);
  168. /*** from parse.c ***/
  169. enum parsedbflags {
  170. pdb_recordavailable =001, /* Store in `available' in-core structures, not `status' */
  171. pdb_rejectstatus =002, /* Throw up an error if `Status' encountered */
  172. pdb_weakclassification=004, /* Ignore priority/section info if we already have any */
  173. pdb_ignorefiles =010 /* Ignore files info if we already have them */
  174. };
  175. const char *illegal_packagename(const char *p, const char **ep);
  176. int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep,
  177. FILE *warnto, int *warncount);
  178. void copy_dependency_links(struct pkginfo *pkg,
  179. struct dependency **updateme,
  180. struct dependency *newdepends,
  181. int available);
  182. /*** from parsehelp.c ***/
  183. struct namevalue {
  184. const char *name;
  185. int value, length;
  186. };
  187. extern const struct namevalue booleaninfos[];
  188. extern const struct namevalue priorityinfos[];
  189. extern const struct namevalue statusinfos[];
  190. extern const struct namevalue eflaginfos[];
  191. extern const struct namevalue wantinfos[];
  192. const char *skip_slash_dotslash(const char *p);
  193. int informativeversion(const struct versionrevision *version);
  194. enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always };
  195. void varbufversion(struct varbuf*, const struct versionrevision*,
  196. enum versiondisplayepochwhen);
  197. const char *parseversion(struct versionrevision *rversion, const char*);
  198. const char *versiondescribe(const struct versionrevision*,
  199. enum versiondisplayepochwhen);
  200. /*** from varbuf.c ***/
  201. struct varbuf;
  202. extern void varbufaddc(struct varbuf *v, int c);
  203. extern void varbufdupc(struct varbuf *v, int c, ssize_t s);
  204. int varbufprintf(struct varbuf *v, const char *fmt, ...) PRINTFFORMAT(2,3);
  205. int varbufvprintf(struct varbuf *v, const char *fmt, va_list va);
  206. void varbufinit(struct varbuf *v);
  207. void varbufreset(struct varbuf *v);
  208. void varbufextend(struct varbuf *v);
  209. void varbuffree(struct varbuf *v);
  210. #define varbufaddstr(v, s) varbufaddbuf(v, s, strlen(s))
  211. extern void varbufaddbuf(struct varbuf *v, const void *s, const int l);
  212. /* varbufinit must be called exactly once before the use of each varbuf
  213. * (including before any call to varbuffree).
  214. *
  215. * However, varbufs allocated `static' are properly initialised anyway and
  216. * do not need varbufinit; multiple consecutive calls to varbufinit before
  217. * any use are allowed.
  218. *
  219. * varbuffree must be called after a varbuf is finished with, if anything
  220. * other than varbufinit has been done. After this you are allowed but
  221. * not required to call varbufinit again if you want to start using the
  222. * varbuf again.
  223. *
  224. * Callers using C++ need not worry about any of this.
  225. */
  226. struct varbuf {
  227. size_t used, size;
  228. char *buf;
  229. #ifdef __cplusplus
  230. void init() { varbufinit(this); }
  231. void free() { varbuffree(this); }
  232. varbuf() { varbufinit(this); }
  233. ~varbuf() { varbuffree(this); }
  234. void operator()(int c) { varbufaddc(this,c); }
  235. void operator()(const char *s) { varbufaddstr(this,s); }
  236. void terminate(void/*to shut 2.6.3 up*/) { varbufaddc(this,0); used--; }
  237. void reset() { used=0; }
  238. const char *string() { terminate(); return buf; }
  239. #endif
  240. };
  241. /*** from dump.c ***/
  242. void writerecord(FILE*, const char*,
  243. const struct pkginfo*, const struct pkginfoperfile*);
  244. void writedb(const char *filename, int available, int mustsync);
  245. void varbufrecord(struct varbuf*, const struct pkginfo*, const struct pkginfoperfile*);
  246. void varbufdependency(struct varbuf *vb, struct dependency *dep);
  247. /* NB THE VARBUF MUST HAVE BEEN INITIALISED AND WILL NOT BE NULL-TERMINATED */
  248. /*** from vercmp.c ***/
  249. int versionsatisfied(struct pkginfoperfile *it, struct deppossi *against);
  250. int versionsatisfied3(const struct versionrevision *it,
  251. const struct versionrevision *ref,
  252. enum depverrel verrel);
  253. int versioncompare(const struct versionrevision *version,
  254. const struct versionrevision *refversion);
  255. int epochsdiffer(const struct versionrevision *a,
  256. const struct versionrevision *b);
  257. /*** from nfmalloc.c ***/
  258. extern void *nfmalloc(size_t);
  259. char *nfstrsave(const char*);
  260. char *nfstrnsave(const char*, int);
  261. void nffreeall(void);
  262. /*** from showpkg.c ***/
  263. struct lstitem;
  264. struct lstitem* parseformat(const char* fmt);
  265. void freeformat(struct lstitem* head);
  266. void show1package(const struct lstitem* head, struct pkginfo *pkg);
  267. #endif /* DPKG_DB_H */