14 #include "lib/jsw/jsw_atree.h"
16 #define ZPM_HASH_STRLEN 64
19 #define ZPM_PATH_MAX PATH_MAX
21 #define ZPM_PATH_MAX 256
24 #define ZPM_LOCAL_DB "/var/lib/zpm/local.db"
26 #define ZPM_PACKAGE_NAME_MAX 191
27 #define ZPM_PACKAGE_VERSION_MAX 58
28 #define ZPM_PACKAGE_RELEASE_MAX 4
29 #define ZPM_PACKAGE_ID_MAX 255
31 #define ZPM_TAG_MAX 15
37 char *path; /* path to db file */
43 struct zpm_package *current_package;
49 char hash[65]; /* length + room for a nul byte */
50 char diskhash[65]; /* hash of actual file on disk */
51 char *target; /* malloced link target */
54 struct zpm_dependency {
55 char minpkg[ZPM_PACKAGE_ID_MAX+1];
56 char maxpkg[ZPM_PACKAGE_ID_MAX+1];
57 struct zpm_dependency *next;
61 char tag[ZPM_TAG_MAX+1];
67 struct jsw_hash_t *ht;
69 /* char pointers are just pointers into the hash table */
70 /* integers/times and such are passed through atoi */
71 /* tags and licenses are trees, NULL if not fetched */
76 /* null if tags not collected */
77 //struct zpm_tree *tags;
81 char *status; /* integer code ? */
82 //struct zpm_tree *licenses;
85 char checksum[ZPM_HASH_STRLEN+1];
86 struct zpm_package *next;
89 int zpm_parse_package(char *pstr, char *name, char *ver, int *rel);
90 char *zpm_findpkg(struct zpm *zpm, char *pkgstr, char *where);
91 char *zpm_findpkg_range(struct zpm *zpm, char *minpkg, char *maxpkg, char *where, int wantleast);
92 int zpm_findhash(struct zpm *zpm, char *find, char *dest);
93 char *zpm_findlib(struct zpm *zpm, char *soname, char *where);
94 int zpm_libraries_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list);
95 int zpm_packages_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list);
96 int zpm_quote(char *value, char *dest, size_t n);
109 //struct zpm_tree *tags;
120 char hash[ZPM_HASH_STRLEN+1];
121 char confhash[ZPM_HASH_STRLEN+1];
122 void *data; /* hook for applications to attach data */
123 struct zpm_file *next; /* so you can make a linked list */
126 int zpm_open(struct zpm *pkg, char *path);
127 int zpm_init(struct zpm *pkg, char *path);
128 int zpm_pkgname(char *base, char *version, int release); /* construct a package file name */
130 /* flags for preserving mode, owner, etc */
131 /* puts hash of import in hash */
132 /* path can be a hash, with an "INTERNAL" flag, i.e. internally import */
134 #define ZPM_OWNER 0x2
135 #define ZPM_MTIME 0x4
136 #define ZPM_INTERNAL 0x8
137 #define ZPM_NOBLOB 0x10
138 /* don't run scripts on install */
139 #define ZPM_NOSCRIPTS 0x10
140 /* don't import file to a particular package */
141 #define ZPM_NOPACKAGE 0x20
143 int zpm_import(struct zpm *zp, char *path, uint32_t flags, char *hash);
145 /* tag a file. relative to "current package" */
146 int zpm_tag(struct zpm *zp, char *path, char *tags);
147 /* should this be broken up into separage functions ? */
148 int zpm_md(struct zpm *zp, char *path, int mode, char *owner, char *group, time_t mtime);
150 /* export hash to dest */
151 int zpm_extract(struct zpm *pkg, char *hash, char *path, mode_t mode);
153 /* export path to dest */
154 int zpm_export(struct zpm *zp, char *path, uint32_t flags, char *dest);
156 int zpm_close(struct zpm *zp);
158 /* attach a signature to a package */
159 int zpm_sign(struct zpm *z, size_t s, void *signature);
161 /* set the package info to the nth package, -1 to return count? */
162 /* further import/exports and such will be relative to this package */
163 int zpm_package(struct zpm *zp, int n);
165 /* get file information */
166 int zpm_stat(struct zpm *z, struct zpm_file *f, int n);
168 //int zpm_newpkg(struct zpm *z, char *base, char *version, int release);
169 int zpm_create_package(struct zpm *zpm, char *name, char *ver, int rel);
170 int zpm_create_pkgid(struct zpm *zpm, char *pkgstr);
173 int zpm_begin(struct zpm *z);
174 int zpm_commit(struct zpm *z);
175 int zpm_rollback(struct zpm *z);
177 /* higher level operations */
179 /* install or uninstall the package */
180 /* flag for keeping the blobs in local */
181 /* what about tag filtering */
182 int zpm_install(struct zpm *z, struct zpm *local, uint32_t flags);
183 int zpm_uninstall(struct zpm *local);
185 /* slurp up the actual blobs */
186 /* what about versioning them if they change */
187 int zpm_preserve(struct zpm *local);
189 /* check file integrity */
190 int zpm_checkinstall(struct zpm *local);
192 int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags);
194 ssize_t uncompresslzma(void *buf, size_t bufsize, int outfd);
195 ssize_t zpm_uncompress_cb(void *buf, size_t bufsize, void *cbdata,
196 int (*cb)(void *ud, void *buf, size_t bufsize));
197 void *compresslzma(void *buf, size_t bufsize, size_t *len);
199 #define SQLERROR(x) fprintf(stderr, "%s %d: %s\n", __func__, __LINE__, (x))
200 int zpm_hash(char *path, char *hash, uint32_t flags);
202 /* hex encoded hash, not null terminated */
203 int zpm_hash_mem(void *mem, size_t size, char *hash);
205 int zpm_readopts(struct zpm *pkg, int ac, char **av);
207 struct zpm_version_info {
209 const char *name; int namelen;
210 const char *version; int verlen;
211 const char *relstr; int rellen;
215 int zpm_parse_version(const char *pstr, struct zpm_version_info *info);
216 int zpm_vercmp(const char *a, const char *b);
218 /* add vercmp collation to db */
219 int zpm_addvercmp(struct zpm *pkg);
221 /* return 1 if database is readonly, 0 if readwrite, or not connected */
222 int zpm_readonly(struct zpm *z);
224 int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg);
226 int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
227 int (*callback)(void *f, int ncols, char **vals, char **cols),
228 void *data, char **errmsg);
230 int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
231 int (*callback)(struct zpm *, struct zpm_file *, void *), void *cbd);
233 int zpm_foreach_package(struct zpm *zpm, char *where,
234 int (*callback)(void *cbdata, int ncols, char **vals, char **cols),
235 void *data, char **errmsg);
237 int zpm_script_hash(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
238 int zpm_script_set(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
239 int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
240 int (*cb)(void *ud, const char *pkg, const char *stage, const char *hash));
242 int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash);
243 int zpm_package_sethash(struct zpm *zpm, char *pkgid, char *hash);
244 int zpm_package_checkhash(struct zpm *zpm, char *pkgid, char *hash);
245 char *zpm_package_gethash(struct zpm *zpm, char *pkgid, char *hash);
246 int zpm_package_clearhash(struct zpm *zpm, char *pkgid);
248 sqlite3_stmt *zpm_dbqueryv(struct zpm *zpm, char *query, va_list args);
249 sqlite3_stmt *zpm_dbquery(struct zpm *zpm, char *query, ...);
250 char *zpm_db_string(struct zpm *zpm, char *query, ...);
251 int zpm_db_int(struct zpm *zpm, char *query, ...);
252 int zpm_db_run(struct zpm *zpm, char *query, ...);
253 void zpm_seterror(struct zpm *zpm, char *msgfmt, ...);
255 struct zpm *zpm_clearmem(struct zpm *zpm);
259 char *ts; /* applications can parse it if they need to */
268 void zpm_note_ack(struct zpm *zpm, int64_t note);
269 void zpm_note_unack(struct zpm *zpm, int64_t note);
270 void zpm_note_del(struct zpm *zpm, int64_t note);
271 int64_t zpm_note(struct zpm *zpm, struct zpm_note *n, unsigned int flags);
272 void zpm_note_free(struct zpm_note *n);
273 int zpm_notes(struct zpm *zpm, int n, struct zpm_note *note);
274 int64_t zpm_note_next(struct zpm *zpm, struct zpm_note *n);
275 int64_t zpm_note_add(struct zpm *zpm, char *pkgid, char *path, char *filehash,
277 int zpm_notes_available(struct zpm *zpm, int flags);