dpkg-db.h 9.7 KB

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