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 int zpm_findhash(struct zpm *zpm, char *find, char *dest);
92 char *zpm_findlib(struct zpm *zpm, char *soname, char *where);
93 int zpm_libraries_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list);
94 int zpm_quote(char *value, char *dest, size_t n);
107 //struct zpm_tree *tags;
118 char hash[ZPM_HASH_STRLEN+1];
119 char confhash[ZPM_HASH_STRLEN+1];
120 void *data; /* hook for applications to attach data */
121 struct zpm_file *next; /* so you can make a linked list */
124 int zpm_open(struct zpm *pkg, char *path);
125 int zpm_init(struct zpm *pkg, char *path);
126 int zpm_pkgname(char *base, char *version, int release); /* construct a package file name */
128 /* flags for preserving mode, owner, etc */
129 /* puts hash of import in hash */
130 /* path can be a hash, with an "INTERNAL" flag, i.e. internally import */
132 #define ZPM_OWNER 0x2
133 #define ZPM_MTIME 0x4
134 #define ZPM_INTERNAL 0x8
135 #define ZPM_NOBLOB 0x10
136 /* don't run scripts on install */
137 #define ZPM_NOSCRIPTS 0x10
138 /* don't import file to a particular package */
139 #define ZPM_NOPACKAGE 0x20
141 int zpm_import(struct zpm *zp, char *path, uint32_t flags, char *hash);
143 /* tag a file. relative to "current package" */
144 int zpm_tag(struct zpm *zp, char *path, char *tags);
145 /* should this be broken up into separage functions ? */
146 int zpm_md(struct zpm *zp, char *path, int mode, char *owner, char *group, time_t mtime);
148 /* export hash to dest */
149 int zpm_extract(struct zpm *pkg, char *hash, char *path, mode_t mode);
151 /* export path to dest */
152 int zpm_export(struct zpm *zp, char *path, uint32_t flags, char *dest);
154 int zpm_close(struct zpm *zp);
156 /* attach a signature to a package */
157 int zpm_sign(struct zpm *z, size_t s, void *signature);
159 /* set the package info to the nth package, -1 to return count? */
160 /* further import/exports and such will be relative to this package */
161 int zpm_package(struct zpm *zp, int n);
163 /* get file information */
164 int zpm_stat(struct zpm *z, struct zpm_file *f, int n);
166 //int zpm_newpkg(struct zpm *z, char *base, char *version, int release);
167 int zpm_create_package(struct zpm *zpm, char *name, char *ver, int rel);
168 int zpm_create_pkgid(struct zpm *zpm, char *pkgstr);
171 int zpm_begin(struct zpm *z);
172 int zpm_commit(struct zpm *z);
173 int zpm_rollback(struct zpm *z);
175 /* higher level operations */
177 /* install or uninstall the package */
178 /* flag for keeping the blobs in local */
179 /* what about tag filtering */
180 int zpm_install(struct zpm *z, struct zpm *local, uint32_t flags);
181 int zpm_uninstall(struct zpm *local);
183 /* slurp up the actual blobs */
184 /* what about versioning them if they change */
185 int zpm_preserve(struct zpm *local);
187 /* check file integrity */
188 int zpm_checkinstall(struct zpm *local);
190 int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags);
192 ssize_t uncompresslzma(void *buf, size_t bufsize, int outfd);
193 void *compresslzma(void *buf, size_t bufsize, size_t *len);
195 #define SQLERROR(x) fprintf(stderr, "%s %d: %s\n", __func__, __LINE__, (x))
196 int zpm_hash(char *path, char *hash, uint32_t flags);
197 int zpm_readopts(struct zpm *pkg, int ac, char **av);
199 int zpm_vercmp(const char *a, const char *b);
201 /* add vercmp collation to db */
202 int zpm_addvercmp(struct zpm *pkg);
204 int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg);
206 int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
207 int (*callback)(void *f, int ncols, char **vals, char **cols),
208 void *data, char **errmsg);
210 int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
211 int (*callback)(struct zpm *, struct zpm_file *, void *), void *cbd);
213 int zpm_foreach_package(struct zpm *zpm, char *where,
214 int (*callback)(void *cbdata, int ncols, char **vals, char **cols),
215 void *data, char **errmsg);
217 int zpm_script_hash(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
218 int zpm_script_set(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
219 int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
220 int (*cb)(void *ud, const char *pkg, const char *stage, const char *hash));
222 int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash);
223 int zpm_package_sethash(struct zpm *zpm, char *pkgid, char *hash);
225 sqlite3_stmt *zpm_dbqueryv(struct zpm *zpm, char *query, va_list args);
226 sqlite3_stmt *zpm_dbquery(struct zpm *zpm, char *query, ...);
227 char *zpm_db_string(struct zpm *zpm, char *query, ...);
228 int zpm_db_int(struct zpm *zpm, char *query, ...);
229 void zpm_db_run(struct zpm *zpm, char *query, ...);
230 void zpm_seterror(struct zpm *zpm, char *msgfmt, ...);
232 struct zpm *zpm_clearmem(struct zpm *zpm);
236 char *ts; /* applications can parse it if they need to */
245 void zpm_note_ack(struct zpm *zpm, int64_t note);
246 void zpm_note_unack(struct zpm *zpm, int64_t note);
247 void zpm_note_del(struct zpm *zpm, int64_t note);
248 int64_t zpm_note(struct zpm *zpm, struct zpm_note *n, unsigned int flags);
249 void zpm_note_free(struct zpm_note *n);
250 int zpm_notes(struct zpm *zpm, int n, struct zpm_note *note);
251 int64_t zpm_note_next(struct zpm *zpm, struct zpm_note *n);
252 int64_t zpm_note_add(struct zpm *zpm, char *pkgid, char *path, char *filehash,
254 int zpm_notes_available(struct zpm *zpm, int flags);