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