]> pd.if.org Git - zpackage/blob - zpm.h
remove stray debug fprintf
[zpackage] / zpm.h
1 #ifndef ZPM_H_
2 #define ZPM_H_ 1
3
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <time.h>
7 #include <limits.h>
8 #include <stdarg.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <unistd.h>
12
13 #include "sqlite3.h"
14 #include "lib/jsw/jsw_atree.h"
15
16 #define ZPM_HASH_STRLEN 64
17
18 #ifdef PATH_MAX
19 #define ZPM_PATH_MAX PATH_MAX
20 #else
21 #define ZPM_PATH_MAX 256
22 #endif
23
24 #define ZPM_LOCAL_DB "/var/lib/zpm/local.db"
25
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
30
31 #define ZPM_TAG_MAX 15
32
33 struct zpm_package;
34
35 struct zpm {
36         sqlite3 *db;
37         char *path; /* path to db file */
38         int error;
39         int dbresult;
40         char *dberrmsg;
41         char *errmsg;
42         char *pkgid;
43         struct zpm_package *current_package;
44 };
45
46 struct zpm_stat {
47         struct stat st;
48         int configuration;
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 */
52 };
53
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;
58 };
59
60 struct zpm_tag {
61         char tag[ZPM_TAG_MAX+1];
62         struct zpm_tag *next;
63 };
64
65 struct zpm_package {
66         struct zpm *zpm;
67         struct jsw_hash_t *ht;
68
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 */
72         char *name;
73         char *version;
74         int release;
75         char *id;
76         /* null if tags not collected */
77         //struct zpm_tree *tags;
78         char *description;
79         char *architecture;
80         char *url;
81         char *status; /* integer code ? */
82         //struct zpm_tree *licenses;
83         time_t build_time;
84         time_t install_time;
85         char checksum[ZPM_HASH_STRLEN+1];
86         struct zpm_package *next;
87 };
88
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);
97
98 struct zpm_file {
99         char *package;
100         char *version;
101         int release;
102
103         char *status;
104         char *path;
105         char *target;
106
107         mode_t mode;
108
109         //struct zpm_tree *tags;
110         
111         char *owner;
112         char *group;
113         gid_t gid;
114         uid_t uid;
115
116         int configuration;
117         time_t mtime;
118         char type;
119         dev_t device;
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 */
124 };
125
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 */
129
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 */
133 #define ZPM_MODE 0x1
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
142
143 int zpm_import(struct zpm *zp, char *path, uint32_t flags, char *hash);
144
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);
149
150 /* export hash to dest */
151 int zpm_extract(struct zpm *pkg, char *hash, char *path, mode_t mode);
152
153 /* export path to dest */
154 int zpm_export(struct zpm *zp, char *path, uint32_t flags, char *dest);
155
156 int zpm_close(struct zpm *zp);
157
158 /* attach a signature to a package */
159 int zpm_sign(struct zpm *z, size_t s, void *signature);
160
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);
164
165 /* get file information */
166 int zpm_stat(struct zpm *z, struct zpm_file *f, int n);
167
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);
171
172 /* transactions */
173 int zpm_begin(struct zpm *z);
174 int zpm_commit(struct zpm *z);
175 int zpm_rollback(struct zpm *z);
176
177 /* higher level operations */
178
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);
184
185 /* slurp up the actual blobs */
186 /* what about versioning them if they change */
187 int zpm_preserve(struct zpm *local);
188
189 /* check file integrity */
190 int zpm_checkinstall(struct zpm *local);
191
192 int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags);
193
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);
198
199 #define SQLERROR(x) fprintf(stderr, "%s %d: %s\n", __func__, __LINE__, (x))
200 int zpm_hash(char *path, char *hash, uint32_t flags);
201
202 /* hex encoded hash, not null terminated */
203 int zpm_hash_mem(void *mem, size_t size, char *hash); 
204
205 int zpm_readopts(struct zpm *pkg, int ac, char **av);
206
207 struct zpm_version_info {
208         const char *verstr;
209         const char *name; int namelen;
210         const char *version; int verlen;
211         const char *relstr; int rellen;
212         int release;
213 };
214
215 int zpm_parse_version(const char *pstr, struct zpm_version_info *info);
216 int zpm_vercmp(const char *a, const char *b);
217
218 /* add vercmp collation to db */
219 int zpm_addvercmp(struct zpm *pkg);
220
221 /* return 1 if database is readonly, 0 if readwrite, or not connected */
222 int zpm_readonly(struct zpm *z);
223
224 int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg);
225
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);
229
230 int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
231 int (*callback)(struct zpm *, struct zpm_file *, void *), void *cbd);
232
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);
236
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));
241
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);
247
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, ...);
254
255 struct zpm *zpm_clearmem(struct zpm *zpm);
256
257 struct zpm_note {
258         int64_t id;
259         char *ts; /* applications can parse it if they need to */
260         char *note;
261         char *pkgid;
262         char *path;
263         char *file;
264         char *hash;
265         int ack;
266 };
267
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,
276                 char *notefmt, ...);
277 int zpm_notes_available(struct zpm *zpm, int flags);
278
279 #endif