]> pd.if.org Git - zpackage/blob - zpm.h
let newpackage set additional fields
[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 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);
95
96 struct zpm_file {
97         char *package;
98         char *version;
99         int release;
100
101         char *status;
102         char *path;
103         char *target;
104
105         mode_t mode;
106
107         //struct zpm_tree *tags;
108         
109         char *owner;
110         char *group;
111         gid_t gid;
112         uid_t uid;
113
114         int configuration;
115         time_t mtime;
116         char type;
117         dev_t device;
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 */
122 };
123
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 */
127
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 */
131 #define ZPM_MODE 0x1
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
140
141 int zpm_import(struct zpm *zp, char *path, uint32_t flags, char *hash);
142
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);
147
148 /* export hash to dest */
149 int zpm_extract(struct zpm *pkg, char *hash, char *path, mode_t mode);
150
151 /* export path to dest */
152 int zpm_export(struct zpm *zp, char *path, uint32_t flags, char *dest);
153
154 int zpm_close(struct zpm *zp);
155
156 /* attach a signature to a package */
157 int zpm_sign(struct zpm *z, size_t s, void *signature);
158
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);
162
163 /* get file information */
164 int zpm_stat(struct zpm *z, struct zpm_file *f, int n);
165
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);
169
170 /* transactions */
171 int zpm_begin(struct zpm *z);
172 int zpm_commit(struct zpm *z);
173 int zpm_rollback(struct zpm *z);
174
175 /* higher level operations */
176
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);
182
183 /* slurp up the actual blobs */
184 /* what about versioning them if they change */
185 int zpm_preserve(struct zpm *local);
186
187 /* check file integrity */
188 int zpm_checkinstall(struct zpm *local);
189
190 int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags);
191
192 ssize_t uncompresslzma(void *buf, size_t bufsize, int outfd);
193 void *compresslzma(void *buf, size_t bufsize, size_t *len);
194
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);
198
199 int zpm_vercmp(const char *a, const char *b);
200
201 /* add vercmp collation to db */
202 int zpm_addvercmp(struct zpm *pkg);
203
204 int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg);
205
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);
209
210 int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
211 int (*callback)(struct zpm *, struct zpm_file *, void *), void *cbd);
212
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);
216
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));
221
222 int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash);
223 int zpm_package_sethash(struct zpm *zpm, char *pkgid, char *hash);
224
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, ...);
231
232 struct zpm *zpm_clearmem(struct zpm *zpm);
233
234 struct zpm_note {
235         int64_t id;
236         char *ts; /* applications can parse it if they need to */
237         char *note;
238         char *pkgid;
239         char *path;
240         char *file;
241         char *hash;
242         int ack;
243 };
244
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,
253                 char *notefmt, ...);
254 int zpm_notes_available(struct zpm *zpm, int flags);
255
256 #endif