home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / live / usr / include / dpkg / dpkg-db.h next >
Encoding:
C/C++ Source or Header  |  1999-03-02  |  9.1 KB  |  304 lines

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