dpkg-db.h 9.1 KB

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