|
krh@27
|
1 |
#define _GNU_SOURCE
|
|
krh@27
|
2 |
|
|
krh@27
|
3 |
#include <string.h>
|
|
krh@27
|
4 |
#include <stdio.h>
|
|
krh@27
|
5 |
#include <sys/stat.h>
|
|
krh@27
|
6 |
#include <sys/mman.h>
|
|
krh@27
|
7 |
#include <unistd.h>
|
|
krh@27
|
8 |
#include <fcntl.h>
|
|
krh@27
|
9 |
#include <errno.h>
|
|
krh@27
|
10 |
|
|
krh@27
|
11 |
#include <expat.h>
|
|
krh@70
|
12 |
#include <zlib.h>
|
|
krh@28
|
13 |
#include <rpm/rpmlib.h>
|
|
krh@28
|
14 |
#include <rpm/rpmdb.h>
|
|
krh@27
|
15 |
#include "sha1.h"
|
|
krh@27
|
16 |
#include "razor.h"
|
|
krh@27
|
17 |
|
|
krh@27
|
18 |
static void
|
|
krh@30
|
19 |
parse_package(struct razor_importer *importer, const char **atts, void *data)
|
|
krh@27
|
20 |
{
|
|
krh@27
|
21 |
const char *name = NULL, *version = NULL;
|
|
krh@27
|
22 |
int i;
|
|
krh@27
|
23 |
|
|
krh@27
|
24 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@27
|
25 |
if (strcmp(atts[i], "name") == 0)
|
|
krh@27
|
26 |
name = atts[i + 1];
|
|
krh@27
|
27 |
else if (strcmp(atts[i], "version") == 0)
|
|
krh@27
|
28 |
version = atts[i + 1];
|
|
krh@27
|
29 |
}
|
|
krh@27
|
30 |
|
|
krh@27
|
31 |
if (name == NULL || version == NULL) {
|
|
krh@27
|
32 |
fprintf(stderr, "invalid package tag, "
|
|
krh@27
|
33 |
"missing name or version attributes\n");
|
|
krh@27
|
34 |
return;
|
|
krh@27
|
35 |
}
|
|
krh@27
|
36 |
|
|
krh@30
|
37 |
razor_importer_begin_package(importer, name, version);
|
|
krh@27
|
38 |
}
|
|
krh@27
|
39 |
|
|
krh@30
|
40 |
enum {
|
|
krh@30
|
41 |
RZR_REQUIRES, RZR_PROVIDES
|
|
krh@30
|
42 |
};
|
|
krh@30
|
43 |
|
|
krh@27
|
44 |
static void
|
|
krh@30
|
45 |
parse_property(struct razor_importer *importer, const char **atts, void *data)
|
|
krh@27
|
46 |
{
|
|
krh@27
|
47 |
const char *name = NULL, *version = NULL;
|
|
krh@27
|
48 |
int i;
|
|
krh@27
|
49 |
|
|
krh@27
|
50 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@27
|
51 |
if (strcmp(atts[i], "name") == 0)
|
|
krh@27
|
52 |
name = atts[i + 1];
|
|
krh@27
|
53 |
if (strcmp(atts[i], "version") == 0)
|
|
krh@27
|
54 |
version = atts[i + 1];
|
|
krh@27
|
55 |
}
|
|
krh@27
|
56 |
|
|
krh@27
|
57 |
if (name == NULL) {
|
|
krh@27
|
58 |
fprintf(stderr, "invalid tag, missing name attribute\n");
|
|
krh@27
|
59 |
return;
|
|
krh@27
|
60 |
}
|
|
krh@27
|
61 |
|
|
krh@30
|
62 |
switch ((int) data) {
|
|
krh@30
|
63 |
case RZR_REQUIRES:
|
|
krh@66
|
64 |
razor_importer_add_property(importer, name, version,
|
|
krh@66
|
65 |
RAZOR_PROPERTY_REQUIRES);
|
|
krh@30
|
66 |
break;
|
|
krh@30
|
67 |
case RZR_PROVIDES:
|
|
krh@66
|
68 |
razor_importer_add_property(importer, name, version,
|
|
krh@66
|
69 |
RAZOR_PROPERTY_PROVIDES);
|
|
krh@30
|
70 |
break;
|
|
krh@30
|
71 |
}
|
|
krh@27
|
72 |
}
|
|
krh@27
|
73 |
|
|
krh@27
|
74 |
static void
|
|
krh@27
|
75 |
start_element(void *data, const char *name, const char **atts)
|
|
krh@27
|
76 |
{
|
|
krh@30
|
77 |
struct razor_importer *importer = data;
|
|
krh@27
|
78 |
|
|
krh@27
|
79 |
if (strcmp(name, "package") == 0)
|
|
krh@30
|
80 |
parse_package(importer, atts, NULL);
|
|
krh@27
|
81 |
else if (strcmp(name, "requires") == 0)
|
|
krh@30
|
82 |
parse_property(importer, atts, (void *) RZR_REQUIRES);
|
|
krh@27
|
83 |
else if (strcmp(name, "provides") == 0)
|
|
krh@30
|
84 |
parse_property(importer, atts, (void*) RZR_PROVIDES);
|
|
krh@27
|
85 |
}
|
|
krh@27
|
86 |
|
|
krh@27
|
87 |
static void
|
|
krh@27
|
88 |
end_element (void *data, const char *name)
|
|
krh@27
|
89 |
{
|
|
krh@30
|
90 |
struct razor_importer *importer = data;
|
|
krh@27
|
91 |
|
|
krh@27
|
92 |
if (strcmp(name, "package") == 0)
|
|
krh@30
|
93 |
razor_importer_finish_package(importer);
|
|
krh@27
|
94 |
}
|
|
krh@27
|
95 |
|
|
krh@27
|
96 |
static int
|
|
krh@30
|
97 |
import_rzr_file(struct razor_importer *importer, const char *filename)
|
|
krh@27
|
98 |
{
|
|
krh@27
|
99 |
SHA_CTX sha1;
|
|
krh@27
|
100 |
XML_Parser parser;
|
|
krh@27
|
101 |
int fd;
|
|
krh@27
|
102 |
void *p;
|
|
krh@27
|
103 |
struct stat stat;
|
|
krh@27
|
104 |
unsigned char hash[20];
|
|
krh@27
|
105 |
|
|
krh@27
|
106 |
fd = open(filename, O_RDONLY);
|
|
krh@27
|
107 |
if (fstat(fd, &stat) < 0)
|
|
krh@27
|
108 |
return -1;
|
|
krh@27
|
109 |
p = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
krh@27
|
110 |
if (p == MAP_FAILED)
|
|
krh@27
|
111 |
return -1;
|
|
krh@27
|
112 |
|
|
krh@27
|
113 |
parser = XML_ParserCreate(NULL);
|
|
krh@30
|
114 |
XML_SetUserData(parser, importer);
|
|
krh@27
|
115 |
XML_SetElementHandler(parser, start_element, end_element);
|
|
krh@27
|
116 |
if (XML_Parse(parser, p, stat.st_size, 1) == XML_STATUS_ERROR) {
|
|
krh@27
|
117 |
fprintf(stderr,
|
|
krh@46
|
118 |
"%s at line %ld, %s\n",
|
|
krh@27
|
119 |
XML_ErrorString(XML_GetErrorCode(parser)),
|
|
krh@27
|
120 |
XML_GetCurrentLineNumber(parser),
|
|
krh@27
|
121 |
filename);
|
|
krh@27
|
122 |
return 1;
|
|
krh@27
|
123 |
}
|
|
krh@27
|
124 |
|
|
krh@27
|
125 |
XML_ParserFree(parser);
|
|
krh@27
|
126 |
|
|
krh@27
|
127 |
SHA1_Init(&sha1);
|
|
krh@27
|
128 |
SHA1_Update(&sha1, p, stat.st_size);
|
|
krh@27
|
129 |
SHA1_Final(hash, &sha1);
|
|
krh@27
|
130 |
|
|
krh@27
|
131 |
close(fd);
|
|
krh@27
|
132 |
|
|
krh@27
|
133 |
munmap(p, stat.st_size);
|
|
krh@27
|
134 |
|
|
krh@27
|
135 |
return 0;
|
|
krh@27
|
136 |
}
|
|
krh@27
|
137 |
|
|
krh@27
|
138 |
struct razor_set *
|
|
krh@27
|
139 |
razor_import_rzr_files(int count, const char *files[])
|
|
krh@27
|
140 |
{
|
|
krh@30
|
141 |
struct razor_importer *importer;
|
|
krh@27
|
142 |
int i;
|
|
krh@27
|
143 |
|
|
krh@30
|
144 |
importer = razor_importer_new();
|
|
krh@27
|
145 |
|
|
krh@27
|
146 |
for (i = 0; i < count; i++) {
|
|
krh@30
|
147 |
if (import_rzr_file(importer, files[i]) < 0) {
|
|
krh@27
|
148 |
fprintf(stderr, "failed to import %s\n", files[i]);
|
|
krh@27
|
149 |
exit(-1);
|
|
krh@27
|
150 |
}
|
|
krh@27
|
151 |
}
|
|
krh@27
|
152 |
|
|
krh@30
|
153 |
return razor_importer_finish(importer);
|
|
krh@27
|
154 |
}
|
|
krh@27
|
155 |
|
|
krh@27
|
156 |
/* Import a yum filelist as a razor package set. */
|
|
krh@27
|
157 |
|
|
krh@27
|
158 |
enum {
|
|
krh@27
|
159 |
YUM_STATE_BEGIN,
|
|
krh@30
|
160 |
YUM_STATE_PACKAGE_NAME,
|
|
krh@70
|
161 |
YUM_STATE_CHECKSUM,
|
|
krh@30
|
162 |
YUM_STATE_REQUIRES,
|
|
krh@46
|
163 |
YUM_STATE_PROVIDES,
|
|
krh@67
|
164 |
YUM_STATE_OBSOLETES,
|
|
krh@67
|
165 |
YUM_STATE_CONFLICTS,
|
|
krh@46
|
166 |
YUM_STATE_FILE
|
|
krh@27
|
167 |
};
|
|
krh@27
|
168 |
|
|
krh@27
|
169 |
struct yum_context {
|
|
krh@70
|
170 |
XML_Parser primary_parser;
|
|
krh@70
|
171 |
XML_Parser filelists_parser;
|
|
krh@70
|
172 |
XML_Parser current_parser;
|
|
krh@70
|
173 |
|
|
krh@30
|
174 |
struct razor_importer *importer;
|
|
krh@27
|
175 |
struct import_property_context *current_property_context;
|
|
krh@48
|
176 |
char name[256], buffer[512], *p;
|
|
krh@70
|
177 |
char pkgid[128];
|
|
krh@27
|
178 |
int state;
|
|
krh@27
|
179 |
};
|
|
krh@27
|
180 |
|
|
krh@27
|
181 |
static void
|
|
krh@70
|
182 |
yum_primary_start_element(void *data, const char *name, const char **atts)
|
|
krh@27
|
183 |
{
|
|
krh@27
|
184 |
struct yum_context *ctx = data;
|
|
krh@62
|
185 |
const char *n, *version, *release;
|
|
krh@62
|
186 |
char buffer[128];
|
|
krh@27
|
187 |
int i;
|
|
krh@27
|
188 |
|
|
krh@27
|
189 |
if (strcmp(name, "name") == 0) {
|
|
krh@27
|
190 |
ctx->state = YUM_STATE_PACKAGE_NAME;
|
|
krh@48
|
191 |
ctx->p = ctx->name;
|
|
krh@27
|
192 |
} else if (strcmp(name, "version") == 0) {
|
|
krh@27
|
193 |
version = NULL;
|
|
krh@62
|
194 |
release = NULL;
|
|
krh@27
|
195 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@27
|
196 |
if (strcmp(atts[i], "ver") == 0)
|
|
krh@27
|
197 |
version = atts[i + 1];
|
|
krh@62
|
198 |
else if (strcmp(atts[i], "rel") == 0)
|
|
krh@62
|
199 |
release = atts[i + 1];
|
|
krh@27
|
200 |
}
|
|
krh@62
|
201 |
if (version == NULL || release == NULL) {
|
|
krh@62
|
202 |
fprintf(stderr, "invalid version tag, "
|
|
krh@62
|
203 |
"missing version or release attribute\n");
|
|
krh@62
|
204 |
return;
|
|
krh@62
|
205 |
}
|
|
krh@62
|
206 |
|
|
krh@62
|
207 |
snprintf(buffer, sizeof buffer, "%s-%s", version, release);
|
|
krh@62
|
208 |
razor_importer_begin_package(ctx->importer, ctx->name, buffer);
|
|
krh@70
|
209 |
} else if (strcmp(name, "checksum") == 0) {
|
|
krh@70
|
210 |
ctx->p = ctx->pkgid;
|
|
krh@70
|
211 |
ctx->state = YUM_STATE_CHECKSUM;
|
|
krh@27
|
212 |
} else if (strcmp(name, "rpm:requires") == 0) {
|
|
krh@30
|
213 |
ctx->state = YUM_STATE_REQUIRES;
|
|
krh@27
|
214 |
} else if (strcmp(name, "rpm:provides") == 0) {
|
|
krh@30
|
215 |
ctx->state = YUM_STATE_PROVIDES;
|
|
krh@67
|
216 |
} else if (strcmp(name, "rpm:obsoletes") == 0) {
|
|
krh@67
|
217 |
ctx->state = YUM_STATE_OBSOLETES;
|
|
krh@67
|
218 |
} else if (strcmp(name, "rpm:conflicts") == 0) {
|
|
krh@67
|
219 |
ctx->state = YUM_STATE_CONFLICTS;
|
|
krh@27
|
220 |
} else if (strcmp(name, "rpm:entry") == 0 &&
|
|
krh@30
|
221 |
ctx->state != YUM_STATE_BEGIN) {
|
|
krh@27
|
222 |
n = NULL;
|
|
krh@27
|
223 |
version = NULL;
|
|
krh@62
|
224 |
release = NULL;
|
|
krh@27
|
225 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@27
|
226 |
if (strcmp(atts[i], "name") == 0)
|
|
krh@27
|
227 |
n = atts[i + 1];
|
|
krh@27
|
228 |
else if (strcmp(atts[i], "ver") == 0)
|
|
krh@27
|
229 |
version = atts[i + 1];
|
|
krh@62
|
230 |
else if (strcmp(atts[i], "rel") == 0)
|
|
krh@62
|
231 |
release = atts[i + 1];
|
|
krh@27
|
232 |
}
|
|
krh@27
|
233 |
|
|
krh@27
|
234 |
if (n == NULL) {
|
|
krh@27
|
235 |
fprintf(stderr, "invalid rpm:entry, "
|
|
krh@27
|
236 |
"missing name or version attributes\n");
|
|
krh@27
|
237 |
return;
|
|
krh@27
|
238 |
}
|
|
krh@27
|
239 |
|
|
krh@62
|
240 |
if (version && release)
|
|
krh@62
|
241 |
snprintf(buffer, sizeof buffer,
|
|
krh@62
|
242 |
"%s-%s", version, release);
|
|
krh@62
|
243 |
else if (version)
|
|
krh@62
|
244 |
strcpy(buffer, version);
|
|
krh@62
|
245 |
else
|
|
krh@62
|
246 |
buffer[0] = '\0';
|
|
krh@62
|
247 |
|
|
krh@30
|
248 |
switch (ctx->state) {
|
|
krh@30
|
249 |
case YUM_STATE_REQUIRES:
|
|
krh@66
|
250 |
razor_importer_add_property(ctx->importer, n, buffer,
|
|
krh@66
|
251 |
RAZOR_PROPERTY_REQUIRES);
|
|
krh@30
|
252 |
break;
|
|
krh@30
|
253 |
case YUM_STATE_PROVIDES:
|
|
krh@66
|
254 |
razor_importer_add_property(ctx->importer, n, buffer,
|
|
krh@66
|
255 |
RAZOR_PROPERTY_PROVIDES);
|
|
krh@30
|
256 |
break;
|
|
krh@67
|
257 |
case YUM_STATE_OBSOLETES:
|
|
krh@67
|
258 |
razor_importer_add_property(ctx->importer, n, buffer,
|
|
krh@67
|
259 |
RAZOR_PROPERTY_OBSOLETES);
|
|
krh@67
|
260 |
break;
|
|
krh@67
|
261 |
case YUM_STATE_CONFLICTS:
|
|
krh@67
|
262 |
razor_importer_add_property(ctx->importer, n, buffer,
|
|
krh@67
|
263 |
RAZOR_PROPERTY_CONFLICTS);
|
|
krh@67
|
264 |
break;
|
|
krh@30
|
265 |
}
|
|
krh@27
|
266 |
}
|
|
krh@27
|
267 |
}
|
|
krh@27
|
268 |
|
|
krh@27
|
269 |
static void
|
|
krh@70
|
270 |
yum_primary_end_element (void *data, const char *name)
|
|
krh@27
|
271 |
{
|
|
krh@27
|
272 |
struct yum_context *ctx = data;
|
|
krh@27
|
273 |
|
|
krh@68
|
274 |
switch (ctx->state) {
|
|
krh@68
|
275 |
case YUM_STATE_PACKAGE_NAME:
|
|
krh@70
|
276 |
case YUM_STATE_CHECKSUM:
|
|
krh@68
|
277 |
case YUM_STATE_FILE:
|
|
krh@68
|
278 |
ctx->state = YUM_STATE_BEGIN;
|
|
krh@68
|
279 |
break;
|
|
krh@68
|
280 |
}
|
|
krh@68
|
281 |
|
|
krh@70
|
282 |
if (strcmp(name, "package") == 0) {
|
|
krh@70
|
283 |
XML_StopParser(ctx->current_parser, XML_TRUE);
|
|
krh@70
|
284 |
ctx->current_parser = ctx->filelists_parser;
|
|
krh@70
|
285 |
}
|
|
krh@27
|
286 |
}
|
|
krh@27
|
287 |
|
|
krh@27
|
288 |
static void
|
|
krh@27
|
289 |
yum_character_data (void *data, const XML_Char *s, int len)
|
|
krh@27
|
290 |
{
|
|
krh@27
|
291 |
struct yum_context *ctx = data;
|
|
krh@27
|
292 |
|
|
krh@48
|
293 |
switch (ctx->state) {
|
|
krh@48
|
294 |
case YUM_STATE_PACKAGE_NAME:
|
|
krh@70
|
295 |
case YUM_STATE_CHECKSUM:
|
|
krh@48
|
296 |
case YUM_STATE_FILE:
|
|
krh@48
|
297 |
memcpy(ctx->p, s, len);
|
|
krh@48
|
298 |
ctx->p += len;
|
|
krh@48
|
299 |
*ctx->p = '\0';
|
|
krh@48
|
300 |
break;
|
|
krh@46
|
301 |
}
|
|
krh@27
|
302 |
}
|
|
krh@27
|
303 |
|
|
krh@70
|
304 |
static void
|
|
krh@70
|
305 |
yum_filelists_start_element(void *data, const char *name, const char **atts)
|
|
krh@70
|
306 |
{
|
|
krh@70
|
307 |
struct yum_context *ctx = data;
|
|
krh@70
|
308 |
const char *pkg, *pkgid;
|
|
krh@70
|
309 |
int i;
|
|
krh@70
|
310 |
|
|
krh@70
|
311 |
if (strcmp(name, "package") == 0) {
|
|
krh@70
|
312 |
pkg = NULL;
|
|
krh@70
|
313 |
pkgid = NULL;
|
|
krh@70
|
314 |
for (i = 0; atts[i]; i += 2) {
|
|
krh@70
|
315 |
if (strcmp(atts[i], "name") == 0)
|
|
krh@70
|
316 |
pkg = atts[i + 1];
|
|
krh@70
|
317 |
else if (strcmp(atts[i], "pkgid") == 0)
|
|
krh@70
|
318 |
pkgid = atts[i + 1];
|
|
krh@70
|
319 |
}
|
|
krh@70
|
320 |
if (strcmp(pkgid, ctx->pkgid) != 0)
|
|
krh@70
|
321 |
fprintf(stderr, "primary.xml and filelists.xml "
|
|
krh@70
|
322 |
"mismatch for %s: %s vs %s",
|
|
krh@70
|
323 |
pkg, pkgid, ctx->pkgid);
|
|
krh@70
|
324 |
} else if (strcmp(name, "file") == 0) {
|
|
krh@70
|
325 |
ctx->state = YUM_STATE_FILE;
|
|
krh@70
|
326 |
ctx->p = ctx->buffer;
|
|
krh@70
|
327 |
}
|
|
krh@70
|
328 |
}
|
|
krh@70
|
329 |
|
|
krh@70
|
330 |
|
|
krh@70
|
331 |
static void
|
|
krh@70
|
332 |
yum_filelists_end_element (void *data, const char *name)
|
|
krh@70
|
333 |
{
|
|
krh@70
|
334 |
struct yum_context *ctx = data;
|
|
krh@70
|
335 |
|
|
krh@70
|
336 |
ctx->state = YUM_STATE_BEGIN;
|
|
krh@70
|
337 |
if (strcmp(name, "package") == 0) {
|
|
krh@70
|
338 |
XML_StopParser(ctx->current_parser, XML_TRUE);
|
|
krh@70
|
339 |
ctx->current_parser = ctx->primary_parser;
|
|
krh@70
|
340 |
razor_importer_finish_package(ctx->importer);
|
|
krh@70
|
341 |
} else if (strcmp(name, "file") == 0)
|
|
krh@70
|
342 |
razor_importer_add_file(ctx->importer, ctx->buffer);
|
|
krh@70
|
343 |
|
|
krh@70
|
344 |
}
|
|
krh@70
|
345 |
|
|
krh@70
|
346 |
#define XML_BUFFER_SIZE 4096
|
|
krh@70
|
347 |
|
|
krh@27
|
348 |
struct razor_set *
|
|
krh@70
|
349 |
razor_set_create_from_yum(void)
|
|
krh@27
|
350 |
{
|
|
krh@27
|
351 |
struct yum_context ctx;
|
|
krh@70
|
352 |
void *buf;
|
|
krh@70
|
353 |
int len, ret;
|
|
krh@70
|
354 |
gzFile primary, filelists;
|
|
krh@70
|
355 |
XML_ParsingStatus status;
|
|
krh@27
|
356 |
|
|
krh@30
|
357 |
ctx.importer = razor_importer_new();
|
|
krh@62
|
358 |
ctx.state = YUM_STATE_BEGIN;
|
|
krh@27
|
359 |
|
|
krh@70
|
360 |
ctx.primary_parser = XML_ParserCreate(NULL);
|
|
krh@70
|
361 |
XML_SetUserData(ctx.primary_parser, &ctx);
|
|
krh@70
|
362 |
XML_SetElementHandler(ctx.primary_parser,
|
|
krh@70
|
363 |
yum_primary_start_element,
|
|
krh@70
|
364 |
yum_primary_end_element);
|
|
krh@70
|
365 |
XML_SetCharacterDataHandler(ctx.primary_parser,
|
|
krh@70
|
366 |
yum_character_data);
|
|
krh@27
|
367 |
|
|
krh@70
|
368 |
ctx.filelists_parser = XML_ParserCreate(NULL);
|
|
krh@70
|
369 |
XML_SetUserData(ctx.filelists_parser, &ctx);
|
|
krh@70
|
370 |
XML_SetElementHandler(ctx.filelists_parser,
|
|
krh@70
|
371 |
yum_filelists_start_element,
|
|
krh@70
|
372 |
yum_filelists_end_element);
|
|
krh@70
|
373 |
XML_SetCharacterDataHandler(ctx.filelists_parser,
|
|
krh@70
|
374 |
yum_character_data);
|
|
krh@70
|
375 |
|
|
krh@70
|
376 |
primary = gzopen("primary.xml.gz", "rb");
|
|
krh@70
|
377 |
if (primary == NULL)
|
|
krh@70
|
378 |
return NULL;
|
|
krh@70
|
379 |
filelists = gzopen("filelists.xml.gz", "rb");
|
|
krh@70
|
380 |
if (filelists == NULL)
|
|
krh@70
|
381 |
return NULL;
|
|
krh@70
|
382 |
|
|
krh@70
|
383 |
ctx.current_parser = ctx.primary_parser;
|
|
krh@70
|
384 |
|
|
krh@70
|
385 |
do {
|
|
krh@70
|
386 |
XML_GetParsingStatus(ctx.current_parser, &status);
|
|
krh@70
|
387 |
switch (status.parsing) {
|
|
krh@70
|
388 |
case XML_SUSPENDED:
|
|
krh@70
|
389 |
ret = XML_ResumeParser(ctx.current_parser);
|
|
krh@27
|
390 |
break;
|
|
krh@70
|
391 |
case XML_PARSING:
|
|
krh@70
|
392 |
case XML_INITIALIZED:
|
|
krh@70
|
393 |
buf = XML_GetBuffer(ctx.current_parser,
|
|
krh@70
|
394 |
XML_BUFFER_SIZE);
|
|
krh@70
|
395 |
if (ctx.current_parser == ctx.primary_parser)
|
|
krh@70
|
396 |
len = gzread(primary, buf, XML_BUFFER_SIZE);
|
|
krh@70
|
397 |
else
|
|
krh@70
|
398 |
len = gzread(filelists, buf, XML_BUFFER_SIZE);
|
|
krh@70
|
399 |
if (len < 0) {
|
|
krh@70
|
400 |
fprintf(stderr,
|
|
krh@70
|
401 |
"couldn't read input: %s\n",
|
|
krh@70
|
402 |
strerror(errno));
|
|
krh@70
|
403 |
return NULL;
|
|
krh@70
|
404 |
}
|
|
krh@27
|
405 |
|
|
krh@70
|
406 |
XML_ParseBuffer(ctx.current_parser, len, len == 0);
|
|
krh@70
|
407 |
break;
|
|
krh@70
|
408 |
case XML_FINISHED:
|
|
krh@70
|
409 |
break;
|
|
krh@27
|
410 |
}
|
|
krh@70
|
411 |
} while (status.parsing != XML_FINISHED);
|
|
krh@27
|
412 |
|
|
krh@70
|
413 |
|
|
krh@70
|
414 |
XML_ParserFree(ctx.primary_parser);
|
|
krh@70
|
415 |
XML_ParserFree(ctx.filelists_parser);
|
|
krh@70
|
416 |
|
|
krh@70
|
417 |
gzclose(primary);
|
|
krh@70
|
418 |
gzclose(filelists);
|
|
krh@27
|
419 |
|
|
krh@30
|
420 |
return razor_importer_finish(ctx.importer);
|
|
krh@27
|
421 |
}
|
|
krh@28
|
422 |
|
|
krh@31
|
423 |
union rpm_entry {
|
|
krh@31
|
424 |
void *p;
|
|
krh@31
|
425 |
char *string;
|
|
krh@31
|
426 |
char **list;
|
|
krh@42
|
427 |
unsigned int *flags;
|
|
krh@31
|
428 |
};
|
|
krh@31
|
429 |
|
|
krh@28
|
430 |
struct razor_set *
|
|
krh@28
|
431 |
razor_set_create_from_rpmdb(void)
|
|
krh@28
|
432 |
{
|
|
krh@30
|
433 |
struct razor_importer *importer;
|
|
krh@28
|
434 |
rpmdbMatchIterator iter;
|
|
krh@28
|
435 |
Header h;
|
|
krh@28
|
436 |
int_32 type, count, i;
|
|
krh@42
|
437 |
union rpm_entry name, version, release;
|
|
krh@42
|
438 |
union rpm_entry property_names, property_versions, property_flags;
|
|
krh@46
|
439 |
union rpm_entry basenames, dirnames, dirindexes;
|
|
krh@46
|
440 |
char filename[PATH_MAX];
|
|
krh@28
|
441 |
rpmdb db;
|
|
krh@28
|
442 |
|
|
krh@28
|
443 |
rpmReadConfigFiles(NULL, NULL);
|
|
krh@28
|
444 |
|
|
krh@28
|
445 |
if (rpmdbOpen("", &db, O_RDONLY, 0644) != 0) {
|
|
krh@28
|
446 |
fprintf(stderr, "cannot open rpm database\n");
|
|
krh@28
|
447 |
exit(1);
|
|
krh@28
|
448 |
}
|
|
krh@28
|
449 |
|
|
krh@30
|
450 |
importer = razor_importer_new();
|
|
krh@28
|
451 |
|
|
krh@28
|
452 |
iter = rpmdbInitIterator(db, 0, NULL, 0);
|
|
krh@28
|
453 |
while (h = rpmdbNextIterator(iter), h != NULL) {
|
|
krh@31
|
454 |
headerGetEntry(h, RPMTAG_NAME, &type, &name.p, &count);
|
|
krh@42
|
455 |
headerGetEntry(h, RPMTAG_VERSION, &type, &version.p, &count);
|
|
krh@31
|
456 |
headerGetEntry(h, RPMTAG_RELEASE, &type, &release.p, &count);
|
|
krh@59
|
457 |
snprintf(filename, sizeof filename, "%s-%s",
|
|
krh@59
|
458 |
version.string, release.string);
|
|
krh@59
|
459 |
razor_importer_begin_package(importer, name.string, filename);
|
|
krh@28
|
460 |
|
|
krh@42
|
461 |
headerGetEntry(h, RPMTAG_REQUIRENAME, &type,
|
|
krh@42
|
462 |
&property_names.p, &count);
|
|
krh@28
|
463 |
headerGetEntry(h, RPMTAG_REQUIREVERSION, &type,
|
|
krh@31
|
464 |
&property_versions.p, &count);
|
|
krh@42
|
465 |
headerGetEntry(h, RPMTAG_REQUIREFLAGS, &type,
|
|
krh@42
|
466 |
&property_flags.p, &count);
|
|
krh@28
|
467 |
for (i = 0; i < count; i++)
|
|
krh@66
|
468 |
razor_importer_add_property(importer,
|
|
krh@42
|
469 |
property_names.list[i],
|
|
krh@66
|
470 |
property_versions.list[i],
|
|
krh@66
|
471 |
RAZOR_PROPERTY_REQUIRES);
|
|
krh@28
|
472 |
|
|
krh@42
|
473 |
headerGetEntry(h, RPMTAG_PROVIDENAME, &type,
|
|
krh@42
|
474 |
&property_names.p, &count);
|
|
krh@28
|
475 |
headerGetEntry(h, RPMTAG_PROVIDEVERSION, &type,
|
|
krh@31
|
476 |
&property_versions.p, &count);
|
|
krh@67
|
477 |
headerGetEntry(h, RPMTAG_PROVIDEFLAGS, &type,
|
|
krh@67
|
478 |
&property_flags.p, &count);
|
|
krh@28
|
479 |
for (i = 0; i < count; i++)
|
|
krh@66
|
480 |
razor_importer_add_property(importer,
|
|
krh@42
|
481 |
property_names.list[i],
|
|
krh@66
|
482 |
property_versions.list[i],
|
|
krh@66
|
483 |
RAZOR_PROPERTY_PROVIDES);
|
|
krh@28
|
484 |
|
|
krh@67
|
485 |
headerGetEntry(h, RPMTAG_OBSOLETENAME, &type,
|
|
krh@67
|
486 |
&property_names.p, &count);
|
|
krh@67
|
487 |
headerGetEntry(h, RPMTAG_OBSOLETEVERSION, &type,
|
|
krh@67
|
488 |
&property_versions.p, &count);
|
|
krh@67
|
489 |
headerGetEntry(h, RPMTAG_OBSOLETEFLAGS, &type,
|
|
krh@67
|
490 |
&property_flags.p, &count);
|
|
krh@67
|
491 |
for (i = 0; i < count; i++)
|
|
krh@67
|
492 |
razor_importer_add_property(importer,
|
|
krh@67
|
493 |
property_names.list[i],
|
|
krh@67
|
494 |
property_versions.list[i],
|
|
krh@67
|
495 |
RAZOR_PROPERTY_OBSOLETES);
|
|
krh@67
|
496 |
|
|
krh@67
|
497 |
headerGetEntry(h, RPMTAG_CONFLICTNAME, &type,
|
|
krh@67
|
498 |
&property_names.p, &count);
|
|
krh@67
|
499 |
headerGetEntry(h, RPMTAG_CONFLICTVERSION, &type,
|
|
krh@67
|
500 |
&property_versions.p, &count);
|
|
krh@67
|
501 |
headerGetEntry(h, RPMTAG_CONFLICTFLAGS, &type,
|
|
krh@67
|
502 |
&property_flags.p, &count);
|
|
krh@67
|
503 |
for (i = 0; i < count; i++)
|
|
krh@67
|
504 |
razor_importer_add_property(importer,
|
|
krh@67
|
505 |
property_names.list[i],
|
|
krh@67
|
506 |
property_versions.list[i],
|
|
krh@67
|
507 |
RAZOR_PROPERTY_CONFLICTS);
|
|
krh@67
|
508 |
|
|
krh@46
|
509 |
headerGetEntry(h, RPMTAG_BASENAMES, &type,
|
|
krh@46
|
510 |
&basenames.p, &count);
|
|
krh@46
|
511 |
headerGetEntry(h, RPMTAG_DIRNAMES, &type,
|
|
krh@46
|
512 |
&dirnames.p, &count);
|
|
krh@46
|
513 |
headerGetEntry(h, RPMTAG_DIRINDEXES, &type,
|
|
krh@46
|
514 |
&dirindexes.p, &count);
|
|
krh@46
|
515 |
for (i = 0; i < count; i++) {
|
|
krh@46
|
516 |
snprintf(filename, sizeof filename, "%s%s",
|
|
krh@46
|
517 |
dirnames.list[dirindexes.flags[i]],
|
|
krh@46
|
518 |
basenames.list[i]);
|
|
krh@46
|
519 |
razor_importer_add_file(importer, filename);
|
|
krh@46
|
520 |
}
|
|
krh@46
|
521 |
|
|
krh@30
|
522 |
razor_importer_finish_package(importer);
|
|
krh@28
|
523 |
}
|
|
krh@28
|
524 |
|
|
krh@28
|
525 |
rpmdbClose(db);
|
|
krh@28
|
526 |
|
|
krh@30
|
527 |
return razor_importer_finish(importer);
|
|
krh@28
|
528 |
}
|