dpkg-db.h 9.6 KB

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