#ifndef ZPM_H_ #define ZPM_H_ 1 #include #include #include #include #include #include #include #include #include "sqlite3.h" #include "lib/jsw/jsw_atree.h" #define ZPM_HASH_STRLEN 64 #ifdef PATH_MAX #define ZPM_PATH_MAX PATH_MAX #else #define ZPM_PATH_MAX 256 #endif #define ZPM_LOCAL_DB "/var/lib/zpm/local.db" #define ZPM_PACKAGE_NAME_MAX 191 #define ZPM_PACKAGE_VERSION_MAX 58 #define ZPM_PACKAGE_RELEASE_MAX 4 #define ZPM_PACKAGE_ID_MAX 255 #define ZPM_TAG_MAX 15 struct zpm_package; struct zpm { sqlite3 *db; char *path; /* path to db file */ int error; int dbresult; char *dberrmsg; char *errmsg; char *pkgid; struct zpm_package *current_package; }; struct zpm_stat { struct stat st; int configuration; char hash[65]; /* length + room for a nul byte */ char diskhash[65]; /* hash of actual file on disk */ char *target; /* malloced link target */ }; struct zpm_dependency { char minpkg[ZPM_PACKAGE_ID_MAX+1]; char maxpkg[ZPM_PACKAGE_ID_MAX+1]; struct zpm_dependency *next; }; struct zpm_tag { char tag[ZPM_TAG_MAX+1]; struct zpm_tag *next; }; struct zpm_package { struct zpm *zpm; struct jsw_hash_t *ht; /* char pointers are just pointers into the hash table */ /* integers/times and such are passed through atoi */ /* tags and licenses are trees, NULL if not fetched */ char *name; char *version; int release; char *id; /* null if tags not collected */ //struct zpm_tree *tags; char *description; char *architecture; char *url; char *status; /* integer code ? */ //struct zpm_tree *licenses; time_t build_time; time_t install_time; char checksum[ZPM_HASH_STRLEN+1]; struct zpm_package *next; }; int zpm_parse_package(char *pstr, char *name, char *ver, int *rel); char *zpm_findpkg(struct zpm *zpm, char *pkgstr, char *where); char *zpm_findpkg_range(struct zpm *zpm, char *minpkg, char *maxpkg, char *where, int wantleast); int zpm_findhash(struct zpm *zpm, char *find, char *dest); char *zpm_findlib(struct zpm *zpm, char *soname, char *where); int zpm_libraries_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list); int zpm_packages_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list); int zpm_quote(char *value, char *dest, size_t n); struct zpm_file { char *package; char *version; int release; char *status; char *path; char *target; mode_t mode; //struct zpm_tree *tags; char *owner; char *group; gid_t gid; uid_t uid; int configuration; time_t mtime; char type; dev_t device; char hash[ZPM_HASH_STRLEN+1]; char confhash[ZPM_HASH_STRLEN+1]; void *data; /* hook for applications to attach data */ struct zpm_file *next; /* so you can make a linked list */ }; int zpm_open(struct zpm *pkg, char *path); int zpm_init(struct zpm *pkg, char *path); int zpm_pkgname(char *base, char *version, int release); /* construct a package file name */ /* flags for preserving mode, owner, etc */ /* puts hash of import in hash */ /* path can be a hash, with an "INTERNAL" flag, i.e. internally import */ #define ZPM_MODE 0x1 #define ZPM_OWNER 0x2 #define ZPM_MTIME 0x4 #define ZPM_INTERNAL 0x8 #define ZPM_NOBLOB 0x10 /* don't run scripts on install */ #define ZPM_NOSCRIPTS 0x10 /* don't import file to a particular package */ #define ZPM_NOPACKAGE 0x20 int zpm_import(struct zpm *zp, char *path, uint32_t flags, char *hash); /* tag a file. relative to "current package" */ int zpm_tag(struct zpm *zp, char *path, char *tags); /* should this be broken up into separage functions ? */ int zpm_md(struct zpm *zp, char *path, int mode, char *owner, char *group, time_t mtime); /* export hash to dest */ int zpm_extract(struct zpm *pkg, char *hash, char *path, mode_t mode); /* export path to dest */ int zpm_export(struct zpm *zp, char *path, uint32_t flags, char *dest); int zpm_close(struct zpm *zp); /* attach a signature to a package */ int zpm_sign(struct zpm *z, size_t s, void *signature); /* set the package info to the nth package, -1 to return count? */ /* further import/exports and such will be relative to this package */ int zpm_package(struct zpm *zp, int n); /* get file information */ int zpm_stat(struct zpm *z, struct zpm_file *f, int n); //int zpm_newpkg(struct zpm *z, char *base, char *version, int release); int zpm_create_package(struct zpm *zpm, char *name, char *ver, int rel); int zpm_create_pkgid(struct zpm *zpm, char *pkgstr); /* transactions */ int zpm_begin(struct zpm *z); int zpm_commit(struct zpm *z); int zpm_rollback(struct zpm *z); /* higher level operations */ /* install or uninstall the package */ /* flag for keeping the blobs in local */ /* what about tag filtering */ int zpm_install(struct zpm *z, struct zpm *local, uint32_t flags); int zpm_uninstall(struct zpm *local); /* slurp up the actual blobs */ /* what about versioning them if they change */ int zpm_preserve(struct zpm *local); /* check file integrity */ int zpm_checkinstall(struct zpm *local); int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags); ssize_t uncompresslzma(void *buf, size_t bufsize, int outfd); ssize_t zpm_uncompress_cb(void *buf, size_t bufsize, void *cbdata, int (*cb)(void *ud, void *buf, size_t bufsize)); void *compresslzma(void *buf, size_t bufsize, size_t *len); #define SQLERROR(x) fprintf(stderr, "%s %d: %s\n", __func__, __LINE__, (x)) int zpm_hash(char *path, char *hash, uint32_t flags); /* hex encoded hash, not null terminated */ int zpm_hash_mem(void *mem, size_t size, char *hash); int zpm_readopts(struct zpm *pkg, int ac, char **av); struct zpm_version_info { const char *verstr; const char *name; int namelen; const char *version; int verlen; const char *relstr; int rellen; int release; }; int zpm_parse_version(const char *pstr, struct zpm_version_info *info); int zpm_vercmp(const char *a, const char *b); /* add vercmp collation to db */ int zpm_addvercmp(struct zpm *pkg); /* return 1 if database is readonly, 0 if readwrite, or not connected */ int zpm_readonly(struct zpm *z); int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg); int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where, int (*callback)(void *f, int ncols, char **vals, char **cols), void *data, char **errmsg); int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where, int (*callback)(struct zpm *, struct zpm_file *, void *), void *cbd); int zpm_foreach_package(struct zpm *zpm, char *where, int (*callback)(void *cbdata, int ncols, char **vals, char **cols), void *data, char **errmsg); int zpm_script_hash(struct zpm *zpm, char *pkgstr, char *phase, char *hash); int zpm_script_set(struct zpm *zpm, char *pkgstr, char *phase, char *hash); int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd, int (*cb)(void *ud, const char *pkg, const char *stage, const char *hash)); int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash); int zpm_package_sethash(struct zpm *zpm, char *pkgid, char *hash); int zpm_package_checkhash(struct zpm *zpm, char *pkgid, char *hash); char *zpm_package_gethash(struct zpm *zpm, char *pkgid, char *hash); int zpm_package_clearhash(struct zpm *zpm, char *pkgid); sqlite3_stmt *zpm_dbqueryv(struct zpm *zpm, char *query, va_list args); sqlite3_stmt *zpm_dbquery(struct zpm *zpm, char *query, ...); char *zpm_db_string(struct zpm *zpm, char *query, ...); int zpm_db_int(struct zpm *zpm, char *query, ...); int zpm_db_run(struct zpm *zpm, char *query, ...); void zpm_seterror(struct zpm *zpm, char *msgfmt, ...); struct zpm *zpm_clearmem(struct zpm *zpm); struct zpm_note { int64_t id; char *ts; /* applications can parse it if they need to */ char *note; char *pkgid; char *path; char *file; char *hash; int ack; }; void zpm_note_ack(struct zpm *zpm, int64_t note); void zpm_note_unack(struct zpm *zpm, int64_t note); void zpm_note_del(struct zpm *zpm, int64_t note); int64_t zpm_note(struct zpm *zpm, struct zpm_note *n, unsigned int flags); void zpm_note_free(struct zpm_note *n); int zpm_notes(struct zpm *zpm, int n, struct zpm_note *note); int64_t zpm_note_next(struct zpm *zpm, struct zpm_note *n); int64_t zpm_note_add(struct zpm *zpm, char *pkgid, char *path, char *filehash, char *notefmt, ...); int zpm_notes_available(struct zpm *zpm, int flags); #endif