dpkg-db.h 9.7 KB

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