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_quote(char *value, char *dest, size_t n);
108 //struct zpm_tree *tags;
119 char hash[ZPM_HASH_STRLEN+1];
120 char confhash[ZPM_HASH_STRLEN+1];
121 void *data; /* hook for applications to attach data */
122 struct zpm_file *next; /* so you can make a linked list */
125 int zpm_open(struct zpm *pkg, char *path);
126 int zpm_init(struct zpm *pkg, char *path);
127 int zpm_pkgname(char *base, char *version, int release); /* construct a package file name */
129 /* flags for preserving mode, owner, etc */
130 /* puts hash of import in hash */
131 /* path can be a hash, with an "INTERNAL" flag, i.e. internally import */
133 #define ZPM_OWNER 0x2
134 #define ZPM_MTIME 0x4
135 #define ZPM_INTERNAL 0x8
136 #define ZPM_NOBLOB 0x10
137 /* don't run scripts on install */
138 #define ZPM_NOSCRIPTS 0x10
139 /* don't import file to a particular package */
140 #define ZPM_NOPACKAGE 0x20
142 int zpm_import(struct zpm *zp, char *path, uint32_t flags, char *hash);
144 /* tag a file. relative to "current package" */
145 int zpm_tag(struct zpm *zp, char *path, char *tags);
146 /* should this be broken up into separage functions ? */
147 int zpm_md(struct zpm *zp, char *path, int mode, char *owner, char *group, time_t mtime);
149 /* export hash to dest */
150 int zpm_extract(struct zpm *pkg, char *hash, char *path, mode_t mode);
152 /* export path to dest */
153 int zpm_export(struct zpm *zp, char *path, uint32_t flags, char *dest);
155 int zpm_close(struct zpm *zp);
157 /* attach a signature to a package */
158 int zpm_sign(struct zpm *z, size_t s, void *signature);
160 /* set the package info to the nth package, -1 to return count? */
161 /* further import/exports and such will be relative to this package */
162 int zpm_package(struct zpm *zp, int n);
164 /* get file information */
165 int zpm_stat(struct zpm *z, struct zpm_file *f, int n);
167 //int zpm_newpkg(struct zpm *z, char *base, char *version, int release);
168 int zpm_create_package(struct zpm *zpm, char *name, char *ver, int rel);
169 int zpm_create_pkgid(struct zpm *zpm, char *pkgstr);
172 int zpm_begin(struct zpm *z);
173 int zpm_commit(struct zpm *z);
174 int zpm_rollback(struct zpm *z);
176 /* higher level operations */
178 /* install or uninstall the package */
179 /* flag for keeping the blobs in local */
180 /* what about tag filtering */
181 int zpm_install(struct zpm *z, struct zpm *local, uint32_t flags);
182 int zpm_uninstall(struct zpm *local);
184 /* slurp up the actual blobs */
185 /* what about versioning them if they change */
186 int zpm_preserve(struct zpm *local);
188 /* check file integrity */
189 int zpm_checkinstall(struct zpm *local);
191 int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags);
193 ssize_t uncompresslzma(void *buf, size_t bufsize, int outfd);
194 void *compresslzma(void *buf, size_t bufsize, size_t *len);
196 #define SQLERROR(x) fprintf(stderr, "%s %d: %s\n", __func__, __LINE__, (x))
197 int zpm_hash(char *path, char *hash, uint32_t flags);
198 int zpm_readopts(struct zpm *pkg, int ac, char **av);
200 int zpm_vercmp(const char *a, const char *b);
202 /* add vercmp collation to db */
203 int zpm_addvercmp(struct zpm *pkg);
205 int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg);
207 int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
208 int (*callback)(void *f, int ncols, char **vals, char **cols),
209 void *data, char **errmsg);
211 int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
212 int (*callback)(struct zpm *, struct zpm_file *, void *), void *cbd);
214 int zpm_foreach_package(struct zpm *zpm, char *where,
215 int (*callback)(void *cbdata, int ncols, char **vals, char **cols),
216 void *data, char **errmsg);
218 int zpm_script_hash(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
219 int zpm_script_set(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
220 int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
221 int (*cb)(void *ud, const char *pkg, const char *stage, const char *hash));
223 int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash);
224 int zpm_package_sethash(struct zpm *zpm, char *pkgid, char *hash);
226 sqlite3_stmt *zpm_dbqueryv(struct zpm *zpm, char *query, va_list args);
227 sqlite3_stmt *zpm_dbquery(struct zpm *zpm, char *query, ...);
228 char *zpm_db_string(struct zpm *zpm, char *query, ...);
229 int zpm_db_int(struct zpm *zpm, char *query, ...);
230 void zpm_db_run(struct zpm *zpm, char *query, ...);
231 void zpm_seterror(struct zpm *zpm, char *msgfmt, ...);
233 struct zpm *zpm_clearmem(struct zpm *zpm);
237 char *ts; /* applications can parse it if they need to */
246 void zpm_note_ack(struct zpm *zpm, int64_t note);
247 void zpm_note_unack(struct zpm *zpm, int64_t note);
248 void zpm_note_del(struct zpm *zpm, int64_t note);
249 int64_t zpm_note(struct zpm *zpm, struct zpm_note *n, unsigned int flags);
250 void zpm_note_free(struct zpm_note *n);
251 int zpm_notes(struct zpm *zpm, int n, struct zpm_note *note);
252 int64_t zpm_note_next(struct zpm *zpm, struct zpm_note *n);
253 int64_t zpm_note_add(struct zpm *zpm, char *pkgid, char *path, char *filehash,
255 int zpm_notes_available(struct zpm *zpm, int flags);