dpkg-db.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. };
  130. /*** from lock.c ***/
  131. void lockdatabase(const char *admindir);
  132. void unlockdatabase(const char *admindir);
  133. /*** from dbmodify.c ***/
  134. enum modstatdb_rw {
  135. /* Those marked with \*s*\ are possible returns from modstatdb_init. */
  136. msdbrw_readonly/*s*/, msdbrw_needsuperuserlockonly/*s*/,
  137. msdbrw_writeifposs,
  138. msdbrw_write/*s*/, msdbrw_needsuperuser,
  139. /* Now some optional flags: */
  140. msdbrw_flagsmask= ~077,
  141. /* flags start at 0100 */
  142. msdbrw_noavail= 0100,
  143. };
  144. struct pipef {
  145. int fd;
  146. struct pipef *next;
  147. };
  148. extern struct pipef *status_pipes;
  149. enum modstatdb_rw modstatdb_init(const char *admindir, enum modstatdb_rw reqrwflags);
  150. void modstatdb_note(struct pkginfo *pkg);
  151. void modstatdb_shutdown(void);
  152. extern char *statusfile, *availablefile; /* initialised by modstatdb_init */
  153. /*** from database.c ***/
  154. struct pkginfo *findpackage(const char *name);
  155. void blankpackage(struct pkginfo *pp);
  156. void blankpackageperfile(struct pkginfoperfile *pifp);
  157. void blankversion(struct versionrevision*);
  158. int informative(struct pkginfo *pkg, struct pkginfoperfile *info);
  159. int countpackages(void);
  160. void resetpackages(void);
  161. struct pkgiterator *iterpkgstart(void);
  162. struct pkginfo *iterpkgnext(struct pkgiterator*);
  163. void iterpkgend(struct pkgiterator*);
  164. void hashreport(FILE*);
  165. /*** from parse.c ***/
  166. enum parsedbflags {
  167. pdb_recordavailable =001, /* Store in `available' in-core structures, not `status' */
  168. pdb_rejectstatus =002, /* Throw up an error if `Status' encountered */
  169. pdb_weakclassification=004, /* Ignore priority/section info if we already have any */
  170. pdb_ignorefiles =010 /* Ignore files info if we already have them */
  171. };
  172. const char *illegal_packagename(const char *p, const char **ep);
  173. int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep,
  174. FILE *warnto, int *warncount);
  175. void copy_dependency_links(struct pkginfo *pkg,
  176. struct dependency **updateme,
  177. struct dependency *newdepends,
  178. int available);
  179. /*** from parsehelp.c ***/
  180. struct namevalue {
  181. const char *name;
  182. int value, length;
  183. };
  184. extern const struct namevalue booleaninfos[];
  185. extern const struct namevalue priorityinfos[];
  186. extern const struct namevalue statusinfos[];
  187. extern const struct namevalue eflaginfos[];
  188. extern const struct namevalue wantinfos[];
  189. const char *skip_slash_dotslash(const char *p);
  190. int informativeversion(const struct versionrevision *version);
  191. enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always };
  192. void varbufversion(struct varbuf*, const struct versionrevision*,
  193. enum versiondisplayepochwhen);
  194. const char *parseversion(struct versionrevision *rversion, const char*);
  195. const char *versiondescribe(const struct versionrevision*,
  196. enum versiondisplayepochwhen);
  197. /*** from varbuf.c ***/
  198. struct varbuf;
  199. extern void varbufaddc(struct varbuf *v, int c);
  200. extern void varbufdupc(struct varbuf *v, int c, ssize_t s);
  201. int varbufprintf(struct varbuf *v, const char *fmt, ...) PRINTFFORMAT(2,3);
  202. int varbufvprintf(struct varbuf *v, const char *fmt, va_list va);
  203. void varbufinit(struct varbuf *v);
  204. void varbufreset(struct varbuf *v);
  205. void varbufextend(struct varbuf *v);
  206. void varbuffree(struct varbuf *v);
  207. #define varbufaddstr(v, s) varbufaddbuf(v, s, strlen(s))
  208. extern void varbufaddbuf(struct varbuf *v, const void *s, const int l);
  209. /* varbufinit must be called exactly once before the use of each varbuf
  210. * (including before any call to varbuffree).
  211. *
  212. * However, varbufs allocated `static' are properly initialised anyway and
  213. * do not need varbufinit; multiple consecutive calls to varbufinit before
  214. * any use are allowed.
  215. *
  216. * varbuffree must be called after a varbuf is finished with, if anything
  217. * other than varbufinit has been done. After this you are allowed but
  218. * not required to call varbufinit again if you want to start using the
  219. * varbuf again.
  220. *
  221. * Callers using C++ need not worry about any of this.
  222. */
  223. struct varbuf {
  224. size_t used, size;
  225. char *buf;
  226. #ifdef __cplusplus
  227. void init() { varbufinit(this); }
  228. void free() { varbuffree(this); }
  229. varbuf() { varbufinit(this); }
  230. ~varbuf() { varbuffree(this); }
  231. void operator()(int c) { varbufaddc(this,c); }
  232. void operator()(const char *s) { varbufaddstr(this,s); }
  233. void terminate(void/*to shut 2.6.3 up*/) { varbufaddc(this,0); used--; }
  234. void reset() { used=0; }
  235. const char *string() { terminate(); return buf; }
  236. #endif
  237. };
  238. /*** from dump.c ***/
  239. void writerecord(FILE*, const char*,
  240. const struct pkginfo*, const struct pkginfoperfile*);
  241. void writedb(const char *filename, int available, int mustsync);
  242. void varbufrecord(struct varbuf*, const struct pkginfo*, const struct pkginfoperfile*);
  243. void varbufdependency(struct varbuf *vb, struct dependency *dep);
  244. /* NB THE VARBUF MUST HAVE BEEN INITIALISED AND WILL NOT BE NULL-TERMINATED */
  245. /*** from vercmp.c ***/
  246. int versionsatisfied(struct pkginfoperfile *it, struct deppossi *against);
  247. int versionsatisfied3(const struct versionrevision *it,
  248. const struct versionrevision *ref,
  249. enum depverrel verrel);
  250. int versioncompare(const struct versionrevision *version,
  251. const struct versionrevision *refversion);
  252. int epochsdiffer(const struct versionrevision *a,
  253. const struct versionrevision *b);
  254. /*** from nfmalloc.c ***/
  255. extern void *nfmalloc(size_t);
  256. char *nfstrsave(const char*);
  257. char *nfstrnsave(const char*, int);
  258. void nffreeall(void);
  259. /*** from showpkg.c ***/
  260. struct lstitem;
  261. struct lstitem* parseformat(const char* fmt);
  262. void freeformat(struct lstitem* head);
  263. void show1package(const struct lstitem* head, struct pkginfo *pkg);
  264. #endif /* DPKG_DB_H */