2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 #include <sys/types.h>
22 #include "repo_updateinfoxml.h"
29 <!-- these tags are available in create repo > 0.9.6 -->
30 <revision>timestamp_or_arbitrary_user_supplied_string</revision>
32 <content>opensuse</content>
33 <content>i386</content>
34 <content>other string</content>
35 <distro cpeid="cpe://o:opensuse_project:opensuse:11">openSUSE 11.0</distro>
40 <location href="repodata/primary.xml.gz"/>
41 <checksum type="sha">e9162516fa25fec8d60caaf4682d2e49967786cc</checksum>
42 <timestamp>1215708444</timestamp>
43 <open-checksum type="sha">c796c48184cd5abc260e4ba929bdf01be14778a7</open-checksum>
45 <data type="filelists">
46 <location href="repodata/filelists.xml.gz"/>
47 <checksum type="sha">1c638295c49e9707c22810004ebb0799791fcf45</checksum>
48 <timestamp>1215708445</timestamp>
49 <open-checksum type="sha">54a40d5db3df0813b8acbe58cea616987eb9dc16</open-checksum>
52 <location href="repodata/other.xml.gz"/>
53 <checksum type="sha">a81ef39eaa70e56048f8351055119d8c82af2491</checksum>
54 <timestamp>1215708447</timestamp>
55 <open-checksum type="sha">4d1ee867c8864025575a2fb8fde3b85371d51978</open-checksum>
57 <data type="deltainfo">
58 <location href="repodata/deltainfo.xml.gz"/>
59 <checksum type="sha">5880cfa5187026a24a552d3c0650904a44908c28</checksum>
60 <timestamp>1215708447</timestamp>
61 <open-checksum type="sha">7c964a2c3b17df5bfdd962c3be952c9ca6978d8b</open-checksum>
63 <data type="updateinfo">
64 <location href="repodata/updateinfo.xml.gz"/>
65 <checksum type="sha">4097f7e25c7bb0770ae31b2471a9c8c077ee904b</checksum>
66 <timestamp>1215708447</timestamp>
67 <open-checksum type="sha">24f8252f3dd041e37e7c3feb2d57e02b4422d316</open-checksum>
69 <data type="diskusage">
70 <location href="repodata/diskusage.xml.gz"/>
71 <checksum type="sha">4097f7e25c7bb0770ae31b2471a9c8c077ee904b</checksum>
72 <timestamp>1215708447</timestamp>
73 <open-checksum type="sha">24f8252f3dd041e37e7c3feb2d57e02b4422d316</open-checksum>
77 support also extension suseinfo format
79 <expire>timestamp</expire>
98 /* normal repomd.xml */
121 /* !! must be sorted by first column !! */
122 static struct stateswitch stateswitches[] = {
124 { STATE_START, "repomd", STATE_REPOMD, 0 },
125 { STATE_START, "suseinfo", STATE_SUSEINFO, 0 },
126 /* we support the tags element in suseinfo in case
127 createrepo version does not support it yet */
128 { STATE_SUSEINFO, "tags", STATE_TAGS, 0 },
129 { STATE_SUSEINFO, "expire", STATE_EXPIRE, 1 },
130 { STATE_SUSEINFO, "keywords", STATE_KEYWORDS, 0 },
131 /* keywords is the suse extension equivalent of
132 tags/content when this one was not yet available.
133 therefore we parse both */
134 { STATE_KEYWORDS, "k", STATE_KEYWORD, 1 },
136 { STATE_REPOMD, "revision", STATE_REVISION, 1 },
137 { STATE_REPOMD, "tags", STATE_TAGS, 0 },
138 { STATE_REPOMD, "data", STATE_DATA, 0 },
140 { STATE_TAGS, "repo", STATE_REPO, 1 },
141 { STATE_TAGS, "content", STATE_CONTENT, 1 },
142 { STATE_TAGS, "distro", STATE_DISTRO, 1 },
143 /* this tag is only valid in suseinfo.xml for now */
144 { STATE_TAGS, "updates", STATE_UPDATES, 1 },
146 { STATE_DATA, "location", STATE_LOCATION, 0 },
147 { STATE_DATA, "checksum", STATE_CHECKSUM, 1 },
148 { STATE_DATA, "timestamp", STATE_TIMESTAMP, 1 },
149 { STATE_DATA, "open-checksum", STATE_OPENCHECKSUM, 1 },
167 struct stateswitch *swtab[NUMSTATES];
168 enum state sbtab[NUMSTATES];
170 /* handles for collection
176 /* repo data handle */
186 static inline const char *
187 find_attr(const char *txt, const char **atts)
189 for (; *atts; atts += 2)
191 if (!strcmp(*atts, txt))
199 startElement(void *userData, const char *name, const char **atts)
201 struct parsedata *pd = userData;
202 /*Pool *pool = pd->pool;*/
203 struct stateswitch *sw;
206 fprintf(stderr, "start: [%d]%s\n", pd->state, name);
208 if (pd->depth != pd->statedepth)
215 if (!pd->swtab[pd->state])
217 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++) /* find name in statetable */
218 if (!strcmp(sw->ename, name))
221 if (sw->from != pd->state)
224 fprintf(stderr, "into unknown: %s (from: %d)\n", name, pd->state);
229 pd->docontent = sw->docontent;
230 pd->statedepth = pd->depth;
236 case STATE_START: break;
241 /* this should be OBSOLETE soon */
242 updstr = find_attr("updates", atts);
245 char *value = strdup(updstr);
246 char *fvalue = value; /* save the first */
249 char *p = strchr(value, ',');
253 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_UPDATES, value);
260 case STATE_SUSEINFO: break;
261 case STATE_EXPIRE: break;
262 case STATE_KEYWORDS: break;
263 case STATE_KEYWORD: break;
264 case STATE_CONTENT: break;
265 case STATE_REVISION: break;
268 /* this is extra metadata about the product this repository
270 const char *cpeid = find_attr("cpeid", atts);
271 pd->rphandle = repodata_new_handle(pd->data);
272 /* set the cpeid for the product
273 the label is set in the content of the tag */
275 repodata_set_poolstr(pd->data, pd->rphandle, REPOSITORY_PRODUCT_CPEID, cpeid);
280 /* this is extra metadata about the product this repository
282 const char *cpeid = find_attr("cpeid", atts);
283 pd->ruhandle = repodata_new_handle(pd->data);
284 /* set the cpeid for the product
285 the label is set in the content of the tag */
287 repodata_set_poolstr(pd->data, pd->ruhandle, REPOSITORY_PRODUCT_CPEID, cpeid);
292 const char *type= find_attr("type", atts);
293 pd->rdhandle = repodata_new_handle(pd->data);
295 repodata_set_poolstr(pd->data, pd->rdhandle, REPOSITORY_REPOMD_TYPE, type);
300 const char *href = find_attr("href", atts);
302 repodata_set_str(pd->data, pd->rdhandle, REPOSITORY_REPOMD_LOCATION, href);
305 case STATE_OPENCHECKSUM:
306 pd->tmpattr= find_attr("type", atts);
315 endElement(void *userData, const char *name)
317 struct parsedata *pd = userData;
318 /* Pool *pool = pd->pool; */
321 fprintf(stderr, "endElement: %s\n", name);
323 if (pd->depth != pd->statedepth)
327 fprintf(stderr, "back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
336 case STATE_START: break;
338 if (pd->timestamp > 0)
339 repodata_set_num(pd->data, SOLVID_META, REPOSITORY_TIMESTAMP, pd->timestamp);
343 repodata_add_flexarray(pd->data, SOLVID_META, REPOSITORY_REPOMD, pd->rdhandle);
346 case STATE_LOCATION: break;
349 case STATE_OPENCHECKSUM:
351 Id type = solv_chksum_str2type(pd->tmpattr);
354 fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
357 if (strlen(pd->content) != 2 * solv_chksum_len(type))
359 fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
362 repodata_set_checksum(pd->data, pd->rdhandle, pd->state == STATE_CHECKSUM ? REPOSITORY_REPOMD_CHECKSUM : REPOSITORY_REPOMD_OPENCHECKSUM, type, pd->content);
366 case STATE_TIMESTAMP:
369 * we want to look for the newest timestamp
370 * of all resources to save it as the time
371 * the metadata was generated
373 int timestamp = atoi(pd->content);
375 repodata_set_num(pd->data, pd->rdhandle, REPOSITORY_REPOMD_TIMESTAMP, timestamp);
376 if (timestamp > pd->timestamp)
377 pd->timestamp = timestamp;
382 int expire = atoi(pd->content);
384 repodata_set_num(pd->data, SOLVID_META, REPOSITORY_EXPIRE, expire);
387 /* repomd.xml content and suseinfo.xml keywords are equivalent */
391 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_KEYWORDS, pd->content);
395 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_REVISION, pd->content);
398 /* distro tag is used in repomd.xml to say the product this repo is
401 repodata_set_str(pd->data, pd->rphandle, REPOSITORY_PRODUCT_LABEL, pd->content);
402 repodata_add_flexarray(pd->data, SOLVID_META, REPOSITORY_DISTROS, pd->rphandle);
405 /* distro tag is used in suseinfo.xml to say the repo updates a product
406 however it s not yet a tag standarized for repomd.xml */
408 repodata_set_str(pd->data, pd->ruhandle, REPOSITORY_PRODUCT_LABEL, pd->content);
409 repodata_add_flexarray(pd->data, SOLVID_META, REPOSITORY_UPDATES, pd->ruhandle);
413 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_REPOID, pd->content);
415 case STATE_SUSEINFO: break;
416 case STATE_KEYWORDS: break;
417 case NUMSTATES: break;
422 pd->state = pd->sbtab[pd->state];
430 characterData(void *userData, const XML_Char *s, int len)
432 struct parsedata *pd = userData;
437 l = pd->lcontent + len + 1;
438 if (l > pd->acontent)
440 pd->content = realloc(pd->content, l + 256);
441 pd->acontent = l + 256;
443 c = pd->content + pd->lcontent;
450 #define BUFF_SIZE 8192
453 repo_add_repomdxml(Repo *repo, FILE *fp, int flags)
455 Pool *pool = repo->pool;
460 struct stateswitch *sw;
462 data = repo_add_repodata(repo, flags);
464 memset(&pd, 0, sizeof(pd));
466 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
468 if (!pd.swtab[sw->from])
469 pd.swtab[sw->from] = sw;
470 pd.sbtab[sw->to] = sw->from;
476 pd.content = malloc(256);
479 XML_Parser parser = XML_ParserCreate(NULL);
480 XML_SetUserData(parser, &pd);
482 XML_SetElementHandler(parser, startElement, endElement);
483 XML_SetCharacterDataHandler(parser, characterData);
486 l = fread(buf, 1, sizeof(buf), fp);
487 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
489 pool_debug(pool, SOLV_FATAL, "repo_repomdxml: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
495 XML_ParserFree(parser);
497 if (!(flags & REPO_NO_INTERNALIZE))
498 repodata_internalize(data);