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