dpkg-db.h 9.1 KB

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