pkg.h (2954B)
1 /* See LICENSE file for copyright and license details. */ 2 #include <archive.h> 3 #include <archive_entry.h> 4 #include <dirent.h> 5 #include <ftw.h> 6 #include <limits.h> 7 #include <regex.h> 8 #include <signal.h> 9 #include <stdarg.h> 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <string.h> 13 #include <sys/types.h> 14 #include <sys/file.h> 15 #include <unistd.h> 16 #include "arg.h" 17 #include "queue.h" 18 19 #define LEN(x) (sizeof (x) / sizeof *(x)) 20 21 #define DBPATH "/var/pkg" 22 #define DBPATHREJECT "/etc/pkgtools/reject.conf" 23 #define ARCHIVEBUFSIZ BUFSIZ 24 25 struct pkgentry { 26 char path[PATH_MAX]; /* absolute path of package entry */ 27 char rpath[PATH_MAX]; /* relative path of package entry */ 28 TAILQ_ENTRY(pkgentry) entry; 29 }; 30 31 struct pkg { 32 char *name; /* package name */ 33 char *version; /* package version */ 34 char path[PATH_MAX]; /* path to package in db or .pkg.tgz */ 35 TAILQ_HEAD(pe_head, pkgentry) pe_head; 36 TAILQ_ENTRY(pkg) entry; 37 }; 38 39 struct rejrule { 40 regex_t preg; 41 TAILQ_ENTRY(rejrule) entry; 42 }; 43 44 struct db { 45 DIR *pkgdir; /* opendir() handle for DBPATH */ 46 char root[PATH_MAX]; /* db root to allow for installation in a mountpoint */ 47 char path[PATH_MAX]; /* absolute path to DBPATH including db root */ 48 TAILQ_HEAD(rejrule_head, rejrule) rejrule_head; 49 TAILQ_HEAD(pkg_head, pkg) pkg_head; 50 TAILQ_HEAD(pkg_rm_head, pkg) pkg_rm_head; 51 }; 52 53 /* db.c */ 54 extern int fflag; 55 extern int vflag; 56 57 /* eprintf.c */ 58 extern char *argv0; 59 60 /* common.c */ 61 void parse_db_name(const char *, char **); 62 void parse_db_version(const char *, char **); 63 void parse_name(const char *, char **); 64 void parse_version(const char *, char **); 65 66 /* db.c */ 67 struct db *db_new(const char *); 68 int db_free(struct db *); 69 int db_add(struct db *, struct pkg *); 70 int db_rm(struct db *, struct pkg *); 71 int db_load(struct db *); 72 struct pkg *pkg_load_file(struct db *, const char *); 73 int db_walk(struct db *, int (*)(struct db *, struct pkg *, void *), void *); 74 int db_links(struct db *, const char *); 75 76 /* ealloc.c */ 77 void *ecalloc(size_t, size_t); 78 void *emalloc(size_t size); 79 void *erealloc(void *, size_t); 80 char *estrdup(const char *); 81 82 /* eprintf.c */ 83 void enprintf(int, const char *, ...); 84 void eprintf(const char *, ...); 85 void weprintf(const char *, ...); 86 87 /* pkg.c */ 88 struct pkg *pkg_load(struct db *, const char *); 89 int pkg_install(struct db *, struct pkg *); 90 int pkg_remove(struct db *, struct pkg *); 91 int pkg_collisions(struct pkg *); 92 struct pkg *pkg_new(const char *, const char *, const char *); 93 void pkg_free(struct pkg *); 94 struct pkgentry *pkgentry_new(struct db *, const char *); 95 void pkgentry_free(struct pkgentry *); 96 97 /* reject.c */ 98 void rej_free(struct db *); 99 int rej_load(struct db *); 100 int rej_match(struct db *, const char *); 101 102 /* strlcat.c */ 103 #undef strlcat 104 size_t strlcat(char *, const char *, size_t); 105 size_t estrlcat(char *, const char *, size_t); 106 107 /* strlcpy.c */ 108 #undef strlcpy 109 size_t strlcpy(char *, const char *, size_t); 110 size_t estrlcpy(char *, const char *, size_t);