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_repomdxml.h"
23 <!-- these tags are available in create repo > 0.9.6 -->
24 <revision>timestamp_or_arbitrary_user_supplied_string</revision>
26 <content>opensuse</content>
27 <content>i386</content>
28 <content>other string</content>
29 <distro cpeid="cpe://o:opensuse_project:opensuse:11">openSUSE 11.0</distro>
34 <location href="repodata/primary.xml.gz"/>
35 <checksum type="sha">e9162516fa25fec8d60caaf4682d2e49967786cc</checksum>
36 <timestamp>1215708444</timestamp>
37 <open-checksum type="sha">c796c48184cd5abc260e4ba929bdf01be14778a7</open-checksum>
39 <data type="filelists">
40 <location href="repodata/filelists.xml.gz"/>
41 <checksum type="sha">1c638295c49e9707c22810004ebb0799791fcf45</checksum>
42 <timestamp>1215708445</timestamp>
43 <open-checksum type="sha">54a40d5db3df0813b8acbe58cea616987eb9dc16</open-checksum>
46 <location href="repodata/other.xml.gz"/>
47 <checksum type="sha">a81ef39eaa70e56048f8351055119d8c82af2491</checksum>
48 <timestamp>1215708447</timestamp>
49 <open-checksum type="sha">4d1ee867c8864025575a2fb8fde3b85371d51978</open-checksum>
51 <data type="deltainfo">
52 <location href="repodata/deltainfo.xml.gz"/>
53 <checksum type="sha">5880cfa5187026a24a552d3c0650904a44908c28</checksum>
54 <timestamp>1215708447</timestamp>
55 <open-checksum type="sha">7c964a2c3b17df5bfdd962c3be952c9ca6978d8b</open-checksum>
57 <data type="updateinfo">
58 <location href="repodata/updateinfo.xml.gz"/>
59 <checksum type="sha">4097f7e25c7bb0770ae31b2471a9c8c077ee904b</checksum>
60 <timestamp>1215708447</timestamp>
61 <open-checksum type="sha">24f8252f3dd041e37e7c3feb2d57e02b4422d316</open-checksum>
63 <data type="diskusage">
64 <location href="repodata/diskusage.xml.gz"/>
65 <checksum type="sha">4097f7e25c7bb0770ae31b2471a9c8c077ee904b</checksum>
66 <timestamp>1215708447</timestamp>
67 <open-checksum type="sha">24f8252f3dd041e37e7c3feb2d57e02b4422d316</open-checksum>
71 support also extension suseinfo format
73 <expire>timestamp</expire>
92 /* normal repomd.xml */
109 static struct solv_xmlparser_element stateswitches[] = {
111 { STATE_START, "repomd", STATE_REPOMD, 0 },
112 { STATE_START, "suseinfo", STATE_SUSEINFO, 0 },
113 /* we support the tags element in suseinfo in case
114 createrepo version does not support it yet */
115 { STATE_SUSEINFO, "tags", STATE_TAGS, 0 },
116 { STATE_SUSEINFO, "expire", STATE_EXPIRE, 1 },
117 { STATE_SUSEINFO, "keywords", STATE_KEYWORDS, 0 },
118 /* keywords is the suse extension equivalent of
119 tags/content when this one was not yet available.
120 therefore we parse both */
121 { STATE_KEYWORDS, "k", STATE_KEYWORD, 1 },
123 { STATE_REPOMD, "revision", STATE_REVISION, 1 },
124 { STATE_REPOMD, "tags", STATE_TAGS, 0 },
125 { STATE_REPOMD, "data", STATE_DATA, 0 },
127 { STATE_TAGS, "repo", STATE_REPO, 1 },
128 { STATE_TAGS, "content", STATE_CONTENT, 1 },
129 { STATE_TAGS, "distro", STATE_DISTRO, 1 },
130 /* this tag is only valid in suseinfo.xml for now */
131 { STATE_TAGS, "updates", STATE_UPDATES, 1 },
133 { STATE_DATA, "location", STATE_LOCATION, 0 },
134 { STATE_DATA, "checksum", STATE_CHECKSUM, 1 },
135 { STATE_DATA, "timestamp", STATE_TIMESTAMP, 1 },
136 { STATE_DATA, "open-checksum", STATE_OPENCHECKSUM, 1 },
137 { STATE_DATA, "size", STATE_SIZE, 1 },
148 struct solv_xmlparser xmlp;
151 /* handles for collection
157 /* repo data handle */
165 startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts)
167 struct parsedata *pd = xmlp->userdata;
175 /* this should be OBSOLETE soon */
176 updstr = solv_xmlparser_find_attr("updates", atts);
179 char *value = solv_strdup(updstr);
180 char *fvalue = value; /* save the first */
183 char *p = strchr(value, ',');
187 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_UPDATES, value);
196 /* this is extra metadata about the product this repository
198 const char *cpeid = solv_xmlparser_find_attr("cpeid", atts);
199 pd->rphandle = repodata_new_handle(pd->data);
200 /* set the cpeid for the product
201 the label is set in the content of the tag */
203 repodata_set_poolstr(pd->data, pd->rphandle, REPOSITORY_PRODUCT_CPEID, cpeid);
208 /* this is extra metadata about the product this repository
210 const char *cpeid = solv_xmlparser_find_attr("cpeid", atts);
211 pd->ruhandle = repodata_new_handle(pd->data);
212 /* set the cpeid for the product
213 the label is set in the content of the tag */
215 repodata_set_poolstr(pd->data, pd->ruhandle, REPOSITORY_PRODUCT_CPEID, cpeid);
220 const char *type= solv_xmlparser_find_attr("type", atts);
221 pd->rdhandle = repodata_new_handle(pd->data);
223 repodata_set_poolstr(pd->data, pd->rdhandle, REPOSITORY_REPOMD_TYPE, type);
228 const char *href = solv_xmlparser_find_attr("href", atts);
230 repodata_set_str(pd->data, pd->rdhandle, REPOSITORY_REPOMD_LOCATION, href);
234 case STATE_OPENCHECKSUM:
236 const char *type= solv_xmlparser_find_attr("type", atts);
237 pd->chksumtype = type && *type ? solv_chksum_str2type(type) : 0;
239 pd->ret = pool_error(pd->pool, -1, "line %d: unknown checksum type: %s", solv_xmlparser_lineno(xmlp), type ? type : "NULL");
249 endElement(struct solv_xmlparser *xmlp, int state, char *content)
251 struct parsedata *pd = xmlp->userdata;
255 if (pd->timestamp > 0)
256 repodata_set_num(pd->data, SOLVID_META, REPOSITORY_TIMESTAMP, pd->timestamp);
260 repodata_add_flexarray(pd->data, SOLVID_META, REPOSITORY_REPOMD, pd->rdhandle);
265 case STATE_OPENCHECKSUM:
268 if (strlen(content) != 2 * solv_chksum_len(pd->chksumtype))
269 pd->ret = pool_error(pd->pool, -1, "line %d: invalid checksum length for %s", solv_xmlparser_lineno(xmlp), solv_chksum_type2str(pd->chksumtype));
271 repodata_set_checksum(pd->data, pd->rdhandle, state == STATE_CHECKSUM ? REPOSITORY_REPOMD_CHECKSUM : REPOSITORY_REPOMD_OPENCHECKSUM, pd->chksumtype, content);
274 case STATE_TIMESTAMP:
277 * we want to look for the newest timestamp
278 * of all resources to save it as the time
279 * the metadata was generated
281 int timestamp = atoi(content);
283 repodata_set_num(pd->data, pd->rdhandle, REPOSITORY_REPOMD_TIMESTAMP, timestamp);
284 if (timestamp > pd->timestamp)
285 pd->timestamp = timestamp;
290 int expire = atoi(content);
292 repodata_set_num(pd->data, SOLVID_META, REPOSITORY_EXPIRE, expire);
295 /* repomd.xml content and suseinfo.xml keywords are equivalent */
299 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_KEYWORDS, content);
303 repodata_set_str(pd->data, SOLVID_META, REPOSITORY_REVISION, content);
306 /* distro tag is used in repomd.xml to say the product this repo is
309 repodata_set_str(pd->data, pd->rphandle, REPOSITORY_PRODUCT_LABEL, content);
310 repodata_add_flexarray(pd->data, SOLVID_META, REPOSITORY_DISTROS, pd->rphandle);
313 /* updates tag is used in suseinfo.xml to say the repo updates a product
314 however it s not yet a tag standarized for repomd.xml */
316 repodata_set_str(pd->data, pd->ruhandle, REPOSITORY_PRODUCT_LABEL, content);
317 repodata_add_flexarray(pd->data, SOLVID_META, REPOSITORY_UPDATES, pd->ruhandle);
321 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_REPOID, content);
325 repodata_set_num(pd->data, pd->rdhandle, REPOSITORY_REPOMD_SIZE, strtoull(content, 0, 10));
333 repo_add_repomdxml(Repo *repo, FILE *fp, int flags)
335 Pool *pool = repo->pool;
339 data = repo_add_repodata(repo, flags);
341 memset(&pd, 0, sizeof(pd));
346 solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
347 if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
348 pd.ret = pool_error(pd.pool, -1, "repo_repomdxml: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
349 solv_xmlparser_free(&pd.xmlp);
351 if (!(flags & REPO_NO_INTERNALIZE))
352 repodata_internalize(data);