]> pd.if.org Git - zpackage/blob - zpm.h
add program to generate a hash of package contents
[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
9 #include <sqlite3.h>
10
11 #define ZPM_HASH_STRLEN 64
12
13 #ifdef PATH_MAX
14 #define ZPM_PATH_MAX PATH_MAX
15 #else
16 #define ZPM_PATH_MAX 256
17 #endif
18
19 #define ZPM_LOCAL_DB "/var/lib/zpm/local.db"
20
21 #define ZPM_PACKAGE_NAME_MAX 191
22 #define ZPM_PACKAGE_VERSION_MAX 58
23 #define ZPM_PACKAGE_RELEASE_MAX 4
24 #define ZPM_PACKAGE_ID_MAX 255
25
26 #define ZPM_TAG_MAX 15
27
28 struct zpm_package;
29
30 struct zpm {
31         sqlite3 *db;
32         char *path; /* path to db file */
33         int error;
34         int dbresult;
35         char *dberrmsg;
36         char *errmsg;
37         char *pkgid;
38         struct zpm_package *current_package;
39 };
40
41 struct zpm_dependency {
42         char minpkg[ZPM_PACKAGE_ID_MAX+1];
43         char maxpkg[ZPM_PACKAGE_ID_MAX+1];
44         struct zpm_dependency *next;
45 };
46
47 struct zpm_tag {
48         char tag[ZPM_TAG_MAX+1];
49         struct zpm_tag *next;
50 };
51
52 struct zpm_package {
53         struct zpm *zpm;
54         struct jsw_hash *ht;
55
56         /* char pointers are just pointers into the hash table */
57         /* integers/times and such are passed through atoi */
58         /* tags and licenses are trees, NULL if not fetched */
59         char *name;
60         char *version;
61         int release;
62         char *id;
63         /* null if tags not collected */
64         //struct zpm_tree *tags;
65         char *description;
66         char *architecture;
67         char *url;
68         char *status; /* integer code ? */
69         //struct zpm_tree *licenses;
70         time_t build_time;
71         time_t install_time;
72         char checksum[ZPM_HASH_STRLEN+1];
73         struct zpm_package *next;
74 };
75
76 int zpm_parse_package(char *pstr, char *name, char *ver, int *rel);
77 char *zpm_findpkg(struct zpm *zpm, char *pkgstr);
78 int zpm_quote(char *value, char *dest, size_t n);
79
80 struct zpm_file {
81         char path[ZPM_PATH_MAX];
82         int mode;
83         //struct zpm_tree *tags;
84         char owner[32];
85         char group[32];
86         time_t mtime;
87         char hash[ZPM_HASH_STRLEN+1];
88         struct zpm_file *next; /* so you can make a linked list */
89 };
90
91 int zpm_open(struct zpm *pkg, char *path);
92 int zpm_init(struct zpm *pkg, char *path);
93 int zpm_pkgname(char *base, char *version, int release); /* construct a package file name */
94
95 /* flags for preserving mode, owner, etc */
96 /* puts hash of import in hash */
97 /* path can be a hash, with an "INTERNAL" flag, i.e. internally import */
98 #define ZPM_MODE 0x1
99 #define ZPM_OWNER 0x2
100 #define ZPM_MTIME 0x4
101 #define ZPM_INTERNAL 0x8
102 #define ZPM_NOBLOB 0x10
103 /* don't run scripts on install */
104 #define ZPM_NOSCRIPTS 0x10
105 /* don't import file to a particular package */
106 #define ZPM_NOPACKAGE 0x20
107
108 int zpm_import(struct zpm *zp, char *path, uint32_t flags, char *hash);
109
110 /* tag a file.  relative to "current package" */
111 int zpm_tag(struct zpm *zp, char *path, char *tags);
112 /* should this be broken up into separage functions ? */
113 int zpm_md(struct zpm *zp, char *path, int mode, char *owner, char *group, time_t mtime);
114
115 /* export hash to dest */
116 int zpm_extract(struct zpm *pkg, char *hash, char *path, int mode);
117
118 /* export path to dest */
119 int zpm_export(struct zpm *zp, char *path, uint32_t flags, char *dest);
120
121 int zpm_close(struct zpm *zp);
122
123 /* attach a signature to a package */
124 int zpm_sign(struct zpm *z, size_t s, void *signature);
125
126 /* set the package info to the nth package, -1 to return count? */
127 /* further import/exports and such will be relative to this package */
128 int zpm_package(struct zpm *zp, int n);
129
130 /* get file information */
131 int zpm_stat(struct zpm *z, struct zpm_file *f, int n);
132
133 /* will also set the package context to the new package */
134 int zpm_newpkg(struct zpm *z, char *base, char *version, int release);
135
136 /* transactions */
137 int zpm_begin(struct zpm *z);
138 int zpm_commit(struct zpm *z);
139 int zpm_rollback(struct zpm *z);
140
141 /* higher level operations */
142
143 /* install or uninstall the package */
144 /* flag for keeping the blobs in local */
145 /* what about tag filtering */
146 int zpm_install(struct zpm *z, struct zpm *local, uint32_t flags);
147 int zpm_uninstall(struct zpm *local);
148
149 /* slurp up the actual blobs */
150 /* what about versioning them if they change */
151 int zpm_preserve(struct zpm *local);
152
153 /* check file integrity */
154 int zpm_checkinstall(struct zpm *local);
155
156 int zpm_merge(struct zpm *z, struct zpm *src, uint32_t flags);
157
158 #if 1
159 void uncompresslzma(void *buf, size_t bufsize, FILE *out);
160 void *compresslzma(void *buf, size_t bufsize, size_t *len);
161 #endif
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, 
175 int (*callback)(void *f, int ncols, char **vals, char **cols),
176 void *data, char **errmsg);
177
178 int zpm_script_hash(struct zpm *zpm, char *pkgstr, char *phase, char *hash);
179 int zpm_package_hash(struct zpm *zpm, char *pkgid, char *hash);
180 int zpm_package_sethash(struct zpm *zpm, char *pkgid, char *hash);
181
182 sqlite3_stmt *zpm_dbquery(struct zpm *zpm, char *query, ...);
183 struct zpm *zpm_clearmem(struct zpm *zpm);
184
185 #endif