2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
17 #include "solv_xmlparser.h"
18 #include "repo_deltainfoxml.h"
22 * <newpackage name="libtool" epoch="0" version="1.5.24" release="6.fc9" arch="i386">
23 * <delta oldepoch="0" oldversion="1.5.24" oldrelease="3.fc8">
24 * <filename>DRPMS/libtool-1.5.24-3.fc8_1.5.24-6.fc9.i386.drpm</filename>
25 * <sequence>libtool-1.5.24-3.fc8-d3571f98b048b1a870e40241bb46c67ab4</sequence>
27 * <checksum type="sha">8f05394695dee9399c204614e21e5f6848990ab7</checksum>
29 * <delta oldepoch="0" oldversion="1.5.22" oldrelease="11.fc7">
30 * <filename>DRPMS/libtool-1.5.22-11.fc7_1.5.24-6.fc9.i386.drpm</filename>
31 * <sequence>libtool-1.5.22-11.fc7-e82691677eee1e83b4812572c5c9ce8eb</sequence>
33 * <checksum type="sha">326658fee45c0baec1e70231046dbaf560f941ce</checksum>
41 STATE_NEWPACKAGE, /* 1 */
43 STATE_FILENAME, /* 3 */
44 STATE_SEQUENCE, /* 4 */
46 STATE_CHECKSUM, /* 6 */
47 STATE_LOCATION, /* 7 */
51 static struct solv_xmlparser_element stateswitches[] = {
52 /* compatibility with old yum-presto */
53 { STATE_START, "prestodelta", STATE_START, 0 },
54 { STATE_START, "deltainfo", STATE_START, 0 },
55 { STATE_START, "newpackage", STATE_NEWPACKAGE, 0 },
56 { STATE_NEWPACKAGE, "delta", STATE_DELTA, 0 },
57 /* compatibility with yum-presto */
58 { STATE_DELTA, "filename", STATE_FILENAME, 1 },
59 { STATE_DELTA, "location", STATE_LOCATION, 0 },
60 { STATE_DELTA, "sequence", STATE_SEQUENCE, 1 },
61 { STATE_DELTA, "size", STATE_SIZE, 1 },
62 { STATE_DELTA, "checksum", STATE_CHECKSUM, 1 },
66 /* Cumulated info about the current deltarpm or patchrpm */
70 unsigned int buildtime;
71 unsigned long long downloadsize;
74 /* Baseversion. deltarpm only has one. */
88 struct deltarpm delta;
96 struct solv_xmlparser xmlp;
101 * create evr (as Id) from 'epoch', 'version' and 'release' attributes
105 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
107 const char *e, *v, *r, *v2;
112 for (; *atts; atts += 2)
114 if (!strcmp(*atts, "oldepoch"))
116 else if (!strcmp(*atts, "epoch"))
118 else if (!strcmp(*atts, "version"))
120 else if (!strcmp(*atts, "oldversion"))
122 else if (!strcmp(*atts, "release"))
124 else if (!strcmp(*atts, "oldrelease"))
127 if (e && (!*e || !strcmp(e, "0")))
131 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
133 if (v2 > v && *v2 == ':')
143 c = space = solv_xmlparser_contentspace(&pd->xmlp, l);
165 fprintf(stderr, "evr: %s\n", space);
167 return pool_str2id(pool, space, 1);
171 startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts)
173 struct parsedata *pd = xmlp->userdata;
174 Pool *pool = pd->pool;
179 case STATE_NEWPACKAGE:
180 if ((str = solv_xmlparser_find_attr("name", atts)) != 0)
181 pd->newpkgname = pool_str2id(pool, str, 1);
182 pd->newpkgevr = makeevr_atts(pool, pd, atts);
183 if ((str = solv_xmlparser_find_attr("arch", atts)) != 0)
184 pd->newpkgarch = pool_str2id(pool, str, 1);
188 memset(&pd->delta, 0, sizeof(pd->delta));
189 pd->delta.bevr = solv_extend(pd->delta.bevr, pd->delta.nbevr, 1, sizeof(Id), 7);
190 pd->delta.bevr[pd->delta.nbevr++] = makeevr_atts(pool, pd, atts);
194 if ((str = solv_xmlparser_find_attr("xml:base", atts)))
195 pd->delta.locbase = solv_strdup(str);
199 pd->delta.location = solv_strdup(solv_xmlparser_find_attr("href", atts));
200 if ((str = solv_xmlparser_find_attr("xml:base", atts)))
201 pd->delta.locbase = solv_strdup(str);
205 pd->delta.filechecksum = 0;
206 pd->delta.filechecksumtype = REPOKEY_TYPE_SHA1;
207 if ((str = solv_xmlparser_find_attr("type", atts)) != 0)
209 pd->delta.filechecksumtype = solv_chksum_str2type(str);
210 if (!pd->delta.filechecksumtype)
211 pool_debug(pool, SOLV_ERROR, "unknown checksum type: '%s'\n", str);
222 endElement(struct solv_xmlparser *xmlp, int state, char *content)
224 struct parsedata *pd = xmlp->userdata;
225 Pool *pool = pd->pool;
232 /* read all data for a deltarpm. commit into attributes */
234 struct deltarpm *d = &pd->delta;
236 handle = repodata_new_handle(pd->data);
237 /* we commit all handles later on in one go so that the
238 * repodata code doesn't need to realloc every time */
239 pd->handles = solv_extend(pd->handles, pd->nhandles, 1, sizeof(Id), 63);
240 pd->handles[pd->nhandles++] = handle;
241 repodata_set_id(pd->data, handle, DELTA_PACKAGE_NAME, pd->newpkgname);
242 repodata_set_id(pd->data, handle, DELTA_PACKAGE_EVR, pd->newpkgevr);
243 repodata_set_id(pd->data, handle, DELTA_PACKAGE_ARCH, pd->newpkgarch);
246 repodata_set_deltalocation(pd->data, handle, 0, 0, d->location);
248 repodata_set_poolstr(pd->data, handle, DELTA_LOCATION_BASE, d->locbase);
251 repodata_set_num(pd->data, handle, DELTA_DOWNLOADSIZE, d->downloadsize);
253 repodata_set_checksum(pd->data, handle, DELTA_CHECKSUM, d->filechecksumtype, d->filechecksum);
256 repodata_set_id(pd->data, handle, DELTA_BASE_EVR, d->bevr[0]);
257 repodata_set_id(pd->data, handle, DELTA_SEQ_NAME, d->seqname);
258 repodata_set_id(pd->data, handle, DELTA_SEQ_EVR, d->seqevr);
259 /* should store as binary blob! */
260 repodata_set_str(pd->data, handle, DELTA_SEQ_NUM, d->seqnum);
263 pd->delta.filechecksum = solv_free(pd->delta.filechecksum);
264 pd->delta.bevr = solv_free(pd->delta.bevr);
266 pd->delta.seqnum = solv_free(pd->delta.seqnum);
267 pd->delta.location = solv_free(pd->delta.location);
268 pd->delta.locbase = solv_free(pd->delta.locbase);
271 pd->delta.location = solv_strdup(content);
274 pd->delta.filechecksum = solv_strdup(content);
277 pd->delta.downloadsize = strtoull(content, 0, 10);
280 if ((str = content) != 0)
283 s1 = strrchr(str, '-');
286 for (s2 = s1 - 1; s2 > str; s2--)
291 for (s2 = s2 - 1; s2 > str; s2--)
296 pd->delta.seqevr = pool_strn2id(pool, s2 + 1, s1 - s2 - 1, 1);
297 pd->delta.seqname = pool_strn2id(pool, str, s2 - str, 1);
302 pd->delta.seqnum = solv_strdup(str);
310 repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags)
312 Pool *pool = repo->pool;
317 data = repo_add_repodata(repo, flags);
319 memset(&pd, 0, sizeof(pd));
323 solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
324 if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
325 pd.ret = pool_error(pd.pool, -1, "repo_deltainfoxml: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
326 solv_xmlparser_free(&pd.xmlp);
328 /* now commit all handles */
330 for (i = 0; i < pd.nhandles; i++)
331 repodata_add_flexarray(pd.data, SOLVID_META, REPOSITORY_DELTAINFO, pd.handles[i]);
332 solv_free(pd.handles);
334 if (!(flags & REPO_NO_INTERNALIZE))
335 repodata_internalize(data);