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