]> pd.if.org Git - zpackage/blob - zpm.h
merge and update cleanup
[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
11 #include "sqlite3.h"
12 #include "lib/jsw/jsw_atree.h"
13
14 #define ZPM_HASH_STRLEN 64
15
16 #ifdef PATH_MAX
17 #define ZPM_PATH_MAX PATH_MAX
18 #else
19 #define ZPM_PATH_MAX 256
20 #endif
21
22 #define ZPM_LOCAL_DB "/var/lib/zpm/local.db"
23
24 #define ZPM_PACKAGE_NAME_MAX 191
25 #define ZPM_PACKAGE_VERSION_MAX 58
26 #define ZPM_PACKAGE_RELEASE_MAX 4
27 #define ZPM_PACKAGE_ID_MAX 255
28
29 #define ZPM_TAG_MAX 15
30
31 struct zpm_package;
32
33 struct zpm {
34         sqlite3 *db;
35         char *path; /* path to db file */
36         int error;
37         int dbresult;
38         char *dberrmsg;
39         char *errmsg;
40         char *pkgid;
41         struct zpm_package *current_package;
42 };
43
44 struct zpm_stat {
45         struct stat st;
46         int configuration;
47         char hash[65]; /* length + room for a nul byte */
48         char diskhash[65]; /* hash of actual file on disk */
49         char *target; /* malloced link target */
50 };
51
52 struct zpm_dependency {
53         char minpkg[ZPM_PACKAGE_ID_MAX+1];
54         char maxpkg[ZPM_PACKAGE_ID_MAX+1];
55         struct zpm_dependency *next;
56 };
57
58 struct zpm_tag {
59         char tag[ZPM_TAG_MAX+1];
60         struct zpm_tag *next;
61 };
62
63 struct zpm_package {
64         struct zpm *zpm;
65         struct jsw_hash_t *ht;
66
67         /* char pointers are just pointers into the hash table */
68         /* integers/times and such are passed through atoi */
69         /* tags and licenses are trees, NULL if not fetched */
70         char *name;
71         char *version;
72         int release;
73         char *id;
74         /* null if tags not collected */
75         //struct zpm_tree *tags;
76         char *description;
77         char *architecture;
78         char *url;
79         char *status; /* integer code ? */
80         //struct zpm_tree *licenses;
81         time_t build_time;
82         time_t install_time;
83         char checksum[ZPM_HASH_STRLEN+1];
84         struct zpm_package *next;
85 };
86
87 int zpm_parse_package(char *pstr, char *name, char *ver, int *rel);
88 char *zpm_findpkg(struct zpm *zpm, char *pkgstr, char *where);
89 int zpm_findhash(struct zpm *zpm, char *find, char *dest);
90 char *zpm_findlib(struct zpm *zpm, char *soname, char *where);
91 int zpm_libraries_needed(struct zpm *zpm, char *pkgid, jsw_atree_t *list); 
92 int zpm_quote(char *value, char *dest, size_t n);
93
94 struct zpm_file {
95         char *package;
96         char *version;
97         int release;
98
99         char *status;
100         char *path;
101         char *target;
102
103         mode_t mode;
104
105         //struct zpm_tree *tags;
106         
107         char *owner;
108         char *group;
109         gid_t gid;
110         uid_t uid;
111
112         int configuration;
113         time_t mtime;
114         char type;
115         dev_t device;
116         char hash[ZPM_HASH_STRLEN+1];
117         char confhash[ZPM_HASH_STRLEN+1];
118         void *data; /* hook for applications to attach data */
119         struct zpm_file *next; /* so you can make a linked list */
120 };
121
122 int zpm_open(struct zpm *pkg, char *path);
123 int zpm_init(struct zpm *pkg, char *path);
124 int zpm_pkgname(char *base, char *version, int release); /* construct a package file name */
125
126 /* flags for preserving mode, owner, etc */
127 /* puts hash of import in hash */
128 /* path can be a hash, with an "INTERNAL" flag, i.e. internally import */
129 #define ZPM_MODE 0x1
130 #define ZPM_OWNER 0x2
131 #define ZPM_MTIME 0x4
132 #define ZPM_INTERNAL 0x8
133 #define ZPM_NOBLOB 0x10
134 /* don't run scripts on install */
135 #define ZPM_NOSCRIPTS 0x10
136 /* don't import file to a particular package */
137 #define ZPM_NOPACKAGE 0x20
138
139 int zpm_import(struct zpm *zp, char *path, uint32_t flags, char *hash);
140
141 /* tag a file.  relative to "current package" */
142 int zpm_tag(struct zpm *zp, char *path, char *tags);
143 /* should this be broken up into separage functions ? */
144 int zpm_md(struct zpm *zp, char *path, int mode, char *owner, char *group, time_t mtime);
145
146 /* export hash to dest */
147 int zpm_extract(struct zpm *pkg, char *hash, char *path, mode_t mode);
148
149 /* export path to dest */
150 int zpm_export(struct zpm *zp, char *path, uint32_t flags, char *dest);
151
152 int zpm_close(struct zpm *zp);
153
154 /* attach a signature to a package */
155 int zpm_sign(struct zpm *z, size_t s, void *signature);
156
157 /* set the package info to the nth package, -1 to return count? */
158 /* further import/exports and such will be relative to this package */
159 int zpm_package(struct zpm *zp, int n);
160
161 /* get file information */
162 int zpm_stat(struct zpm *z, struct zpm_file *f, int n);
163
164 //int zpm_newpkg(struct zpm *z, char *base, char *version, int release);
165 int zpm_create_package(struct zpm *zpm, char *name, char *ver, int rel); 
166 int zpm_create_pkgid(struct zpm *zpm, char *pkgstr);
167
168 /* transactions */
169 int zpm_begin(struct zpm *z);
170 int zpm_commit(struct zpm *z);
171 int zpm_rollback(struct zpm *z);
172
173 /* higher level operations */
174
175 /* install or uninstall the package */
176 /* flag for keeping the blobs in local */
177 /* what about tag filtering */
178 int zpm_install(struct zpm *z, struct zpm *local, uint32_t flags);
179 int zpm_uninstall(struct zpm *local);
180
181 /* slurp up the actual blobs */
182 /* what about versioning them if they change */
183 int zpm_preserve(struct zpm *local);
184
185 /* check file integrity */
186 int zpm_checkinstall(struct zpm *local);
187
188 int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags);
189
190 ssize_t uncompresslzma(void *buf, size_t bufsize, int outfd);
191 void *compresslzma(void *buf, size_t bufsize, size_t *len);
192
193 #define SQLERROR(x) fprintf(stderr, "%s %d: %s\n", __func__, __LINE__, (x))
194 int zpm_hash(char *path, char *hash, uint32_t flags);
195 int zpm_readopts(struct zpm *pkg, int ac, char **av);
196
197 int zpm_vercmp(const char *a, const char *b);
198
199 /* add vercmp collation to db */
200 int zpm_addvercmp(struct zpm *pkg);
201
202 int zpm_exec(struct zpm *z, const char *sql, int(*callback)(void *, int, char **, char**), void *arg, char **errmsg);
203
204 int zpm_foreach_path(struct zpm *zpm, char *pkgid, char *where,
205 int (*callback)(void *f, int ncols, char **vals, char **cols),
206 void *data, char **errmsg);
207
208 int zpm_foreach_path_ds(struct zpm *zpm, char *pkgid, char *where,
209 int (*callback)(struct zpm *, struct zpm_file *, void *), void *cbd);
210
211 int zpm_foreach_package(struct zpm *zpm, char *where,
212 int (*callback)(void *cbdata, int ncols, char **vals, char **cols),
213 void *data, char **errmsg);
214
215 int zpm_script_hash(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
216 int zpm_script_set(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
217 int zpm_foreach_script(struct zpm *zpm, char *pkgstr, char *stage, void *cbd,
218                 int (*cb)(void *ud, const char *pkg, const char *stage, const char *hash));
219
220 int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash);
221 int zpm_package_sethash(struct zpm *zpm, char *pkgid, char *hash);
222
223 sqlite3_stmt *zpm_dbqueryv(struct zpm *zpm, char *query, va_list args);
224 sqlite3_stmt *zpm_dbquery(struct zpm *zpm, char *query, ...);
225 char *zpm_db_string(struct zpm *zpm, char *query, ...);
226 int zpm_db_int(struct zpm *zpm, char *query, ...);
227 void zpm_db_run(struct zpm *zpm, char *query, ...);
228 void zpm_seterror(struct zpm *zpm, char *msgfmt, ...);
229
230 struct zpm *zpm_clearmem(struct zpm *zpm);
231
232 struct zpm_note {
233         int64_t id;
234         char *ts; /* applications can parse it if they need to */
235         char *note;
236         char *pkgid;
237         char *path;
238         char *file;
239         char *hash;
240         int ack;
241 };
242
243 void zpm_note_ack(struct zpm *zpm, int64_t note);
244 void zpm_note_unack(struct zpm *zpm, int64_t note);
245 void zpm_note_del(struct zpm *zpm, int64_t note);
246 int64_t zpm_note(struct zpm *zpm, struct zpm_note *n, unsigned int flags);
247 void zpm_note_free(struct zpm_note *n);
248 int zpm_notes(struct zpm *zpm, int n, struct zpm_note *note);
249 int64_t zpm_note_next(struct zpm *zpm, struct zpm_note *n);
250 int64_t zpm_note_add(struct zpm *zpm, char *pkgid, char *path, char *filehash,
251                 char *notefmt, ...);
252 int zpm_notes_available(struct zpm *zpm, int flags);
253
254 #endif