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