dpkg-db.h 9.1 KB

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