1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
/*
* Copyright (c) 2007, Novell Inc.
*
* This program is licensed under the BSD license, read LICENSE.BSD
* for further information
*/
#define _GNU_SOURCE
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pool.h"
#include "repo.h"
#include "chksum.h"
#include "solv_xmlparser.h"
#include "repo_deltainfoxml.h"
/*
* <deltainfo>
* <newpackage name="libtool" epoch="0" version="1.5.24" release="6.fc9" arch="i386">
* <delta oldepoch="0" oldversion="1.5.24" oldrelease="3.fc8">
* <filename>DRPMS/libtool-1.5.24-3.fc8_1.5.24-6.fc9.i386.drpm</filename>
* <sequence>libtool-1.5.24-3.fc8-d3571f98b048b1a870e40241bb46c67ab4</sequence>
* <size>22452</size>
* <checksum type="sha">8f05394695dee9399c204614e21e5f6848990ab7</checksum>
* </delta>
* <delta oldepoch="0" oldversion="1.5.22" oldrelease="11.fc7">
* <filename>DRPMS/libtool-1.5.22-11.fc7_1.5.24-6.fc9.i386.drpm</filename>
* <sequence>libtool-1.5.22-11.fc7-e82691677eee1e83b4812572c5c9ce8eb</sequence>
* <size>110362</size>
* <checksum type="sha">326658fee45c0baec1e70231046dbaf560f941ce</checksum>
* </delta>
* </newpackage>
* </deltainfo>
*/
enum state {
STATE_START,
STATE_NEWPACKAGE, /* 1 */
STATE_DELTA, /* 2 */
STATE_FILENAME, /* 3 */
STATE_SEQUENCE, /* 4 */
STATE_SIZE, /* 5 */
STATE_CHECKSUM, /* 6 */
STATE_LOCATION, /* 7 */
NUMSTATES
};
static struct solv_xmlparser_element stateswitches[] = {
/* compatibility with old yum-presto */
{ STATE_START, "prestodelta", STATE_START, 0 },
{ STATE_START, "deltainfo", STATE_START, 0 },
{ STATE_START, "newpackage", STATE_NEWPACKAGE, 0 },
{ STATE_NEWPACKAGE, "delta", STATE_DELTA, 0 },
/* compatibility with yum-presto */
{ STATE_DELTA, "filename", STATE_FILENAME, 1 },
{ STATE_DELTA, "location", STATE_LOCATION, 0 },
{ STATE_DELTA, "sequence", STATE_SEQUENCE, 1 },
{ STATE_DELTA, "size", STATE_SIZE, 1 },
{ STATE_DELTA, "checksum", STATE_CHECKSUM, 1 },
{ NUMSTATES }
};
/* Cumulated info about the current deltarpm or patchrpm */
struct deltarpm {
char *location;
char *locbase;
unsigned int buildtime;
unsigned long long downloadsize;
char *filechecksum;
int filechecksumtype;
/* Baseversion. deltarpm only has one. */
Id *bevr;
unsigned nbevr;
Id seqname;
Id seqevr;
char *seqnum;
};
struct parsedata {
int ret;
Pool *pool;
Repo *repo;
Repodata *data;
struct deltarpm delta;
Id newpkgevr;
Id newpkgname;
Id newpkgarch;
Id *handles;
int nhandles;
struct solv_xmlparser xmlp;
};
/*
* create evr (as Id) from 'epoch', 'version' and 'release' attributes
*/
static Id
makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
{
const char *e, *v, *r, *v2;
char *c, *space;
int l;
e = v = r = 0;
for (; *atts; atts += 2)
{
if (!strcmp(*atts, "oldepoch"))
e = atts[1];
else if (!strcmp(*atts, "epoch"))
e = atts[1];
else if (!strcmp(*atts, "version"))
v = atts[1];
else if (!strcmp(*atts, "oldversion"))
v = atts[1];
else if (!strcmp(*atts, "release"))
r = atts[1];
else if (!strcmp(*atts, "oldrelease"))
r = atts[1];
}
if (e && (!*e || !strcmp(e, "0")))
e = 0;
if (v && !e)
{
for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
;
if (v2 > v && *v2 == ':')
e = "0";
}
l = 1;
if (e)
l += strlen(e) + 1;
if (v)
l += strlen(v);
if (r)
l += strlen(r) + 1;
c = space = solv_xmlparser_contentspace(&pd->xmlp, l);
if (e)
{
strcpy(c, e);
c += strlen(c);
*c++ = ':';
}
if (v)
{
strcpy(c, v);
c += strlen(c);
}
if (r)
{
*c++ = '-';
strcpy(c, r);
c += strlen(c);
}
*c = 0;
if (!*space)
return 0;
#if 0
fprintf(stderr, "evr: %s\n", space);
#endif
return pool_str2id(pool, space, 1);
}
static void
startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts)
{
struct parsedata *pd = xmlp->userdata;
Pool *pool = pd->pool;
const char *str;
switch(state)
{
case STATE_NEWPACKAGE:
if ((str = solv_xmlparser_find_attr("name", atts)) != 0)
pd->newpkgname = pool_str2id(pool, str, 1);
pd->newpkgevr = makeevr_atts(pool, pd, atts);
if ((str = solv_xmlparser_find_attr("arch", atts)) != 0)
pd->newpkgarch = pool_str2id(pool, str, 1);
break;
case STATE_DELTA:
memset(&pd->delta, 0, sizeof(pd->delta));
pd->delta.bevr = solv_extend(pd->delta.bevr, pd->delta.nbevr, 1, sizeof(Id), 7);
pd->delta.bevr[pd->delta.nbevr++] = makeevr_atts(pool, pd, atts);
break;
case STATE_FILENAME:
if ((str = solv_xmlparser_find_attr("xml:base", atts)))
pd->delta.locbase = solv_strdup(str);
break;
case STATE_LOCATION:
pd->delta.location = solv_strdup(solv_xmlparser_find_attr("href", atts));
if ((str = solv_xmlparser_find_attr("xml:base", atts)))
pd->delta.locbase = solv_strdup(str);
break;
case STATE_CHECKSUM:
pd->delta.filechecksum = 0;
pd->delta.filechecksumtype = REPOKEY_TYPE_SHA1;
if ((str = solv_xmlparser_find_attr("type", atts)) != 0)
{
pd->delta.filechecksumtype = solv_chksum_str2type(str);
if (!pd->delta.filechecksumtype)
pool_debug(pool, SOLV_ERROR, "unknown checksum type: '%s'\n", str);
}
break;
default:
break;
}
}
static void
endElement(struct solv_xmlparser *xmlp, int state, char *content)
{
struct parsedata *pd = xmlp->userdata;
Pool *pool = pd->pool;
const char *str;
switch (state)
{
case STATE_DELTA:
{
/* read all data for a deltarpm. commit into attributes */
Id handle;
struct deltarpm *d = &pd->delta;
handle = repodata_new_handle(pd->data);
/* we commit all handles later on in one go so that the
* repodata code doesn't need to realloc every time */
pd->handles = solv_extend(pd->handles, pd->nhandles, 1, sizeof(Id), 63);
pd->handles[pd->nhandles++] = handle;
repodata_set_id(pd->data, handle, DELTA_PACKAGE_NAME, pd->newpkgname);
repodata_set_id(pd->data, handle, DELTA_PACKAGE_EVR, pd->newpkgevr);
repodata_set_id(pd->data, handle, DELTA_PACKAGE_ARCH, pd->newpkgarch);
if (d->location)
{
repodata_set_deltalocation(pd->data, handle, 0, 0, d->location);
if (d->locbase)
repodata_set_poolstr(pd->data, handle, DELTA_LOCATION_BASE, d->locbase);
}
if (d->downloadsize)
repodata_set_num(pd->data, handle, DELTA_DOWNLOADSIZE, d->downloadsize);
if (d->filechecksum)
repodata_set_checksum(pd->data, handle, DELTA_CHECKSUM, d->filechecksumtype, d->filechecksum);
if (d->seqnum)
{
repodata_set_id(pd->data, handle, DELTA_BASE_EVR, d->bevr[0]);
repodata_set_id(pd->data, handle, DELTA_SEQ_NAME, d->seqname);
repodata_set_id(pd->data, handle, DELTA_SEQ_EVR, d->seqevr);
/* should store as binary blob! */
repodata_set_str(pd->data, handle, DELTA_SEQ_NUM, d->seqnum);
}
}
pd->delta.filechecksum = solv_free(pd->delta.filechecksum);
pd->delta.bevr = solv_free(pd->delta.bevr);
pd->delta.nbevr = 0;
pd->delta.seqnum = solv_free(pd->delta.seqnum);
pd->delta.location = solv_free(pd->delta.location);
pd->delta.locbase = solv_free(pd->delta.locbase);
break;
case STATE_FILENAME:
pd->delta.location = solv_strdup(content);
break;
case STATE_CHECKSUM:
pd->delta.filechecksum = solv_strdup(content);
break;
case STATE_SIZE:
pd->delta.downloadsize = strtoull(content, 0, 10);
break;
case STATE_SEQUENCE:
if ((str = content) != 0)
{
const char *s1, *s2;
s1 = strrchr(str, '-');
if (s1)
{
for (s2 = s1 - 1; s2 > str; s2--)
if (*s2 == '-')
break;
if (*s2 == '-')
{
for (s2 = s2 - 1; s2 > str; s2--)
if (*s2 == '-')
break;
if (*s2 == '-')
{
pd->delta.seqevr = pool_strn2id(pool, s2 + 1, s1 - s2 - 1, 1);
pd->delta.seqname = pool_strn2id(pool, str, s2 - str, 1);
str = s1 + 1;
}
}
}
pd->delta.seqnum = solv_strdup(str);
}
default:
break;
}
}
int
repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags)
{
Pool *pool = repo->pool;
Repodata *data;
struct parsedata pd;
int i;
data = repo_add_repodata(repo, flags);
memset(&pd, 0, sizeof(pd));
pd.pool = pool;
pd.repo = repo;
pd.data = data;
solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
pd.ret = pool_error(pd.pool, -1, "repo_deltainfoxml: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
solv_xmlparser_free(&pd.xmlp);
/* now commit all handles */
if (!pd.ret)
for (i = 0; i < pd.nhandles; i++)
repodata_add_flexarray(pd.data, SOLVID_META, REPOSITORY_DELTAINFO, pd.handles[i]);
solv_free(pd.handles);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
return pd.ret;
}
/* EOF */
|