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