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