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>
21 #include "repo_updateinfoxml.h"
28 <!-- these tags are available in create repo > 0.9.6 -->
29 <revision>timestamp_or_arbitrary_user_supplied_string</revision>
31 <content>opensuse</content>
32 <content>i386</content>
33 <content>other string</content>
34 <distro cpeid="cpe://o:opensuse_project:opensuse:11">openSUSE 11.0</distro>
39 <location href="repodata/primary.xml.gz"/>
40 <checksum type="sha">e9162516fa25fec8d60caaf4682d2e49967786cc</checksum>
41 <timestamp>1215708444</timestamp>
42 <open-checksum type="sha">c796c48184cd5abc260e4ba929bdf01be14778a7</open-checksum>
44 <data type="filelists">
45 <location href="repodata/filelists.xml.gz"/>
46 <checksum type="sha">1c638295c49e9707c22810004ebb0799791fcf45</checksum>
47 <timestamp>1215708445</timestamp>
48 <open-checksum type="sha">54a40d5db3df0813b8acbe58cea616987eb9dc16</open-checksum>
51 <location href="repodata/other.xml.gz"/>
52 <checksum type="sha">a81ef39eaa70e56048f8351055119d8c82af2491</checksum>
53 <timestamp>1215708447</timestamp>
54 <open-checksum type="sha">4d1ee867c8864025575a2fb8fde3b85371d51978</open-checksum>
56 <data type="deltainfo">
57 <location href="repodata/deltainfo.xml.gz"/>
58 <checksum type="sha">5880cfa5187026a24a552d3c0650904a44908c28</checksum>
59 <timestamp>1215708447</timestamp>
60 <open-checksum type="sha">7c964a2c3b17df5bfdd962c3be952c9ca6978d8b</open-checksum>
62 <data type="updateinfo">
63 <location href="repodata/updateinfo.xml.gz"/>
64 <checksum type="sha">4097f7e25c7bb0770ae31b2471a9c8c077ee904b</checksum>
65 <timestamp>1215708447</timestamp>
66 <open-checksum type="sha">24f8252f3dd041e37e7c3feb2d57e02b4422d316</open-checksum>
68 <data type="diskusage">
69 <location href="repodata/diskusage.xml.gz"/>
70 <checksum type="sha">4097f7e25c7bb0770ae31b2471a9c8c077ee904b</checksum>
71 <timestamp>1215708447</timestamp>
72 <open-checksum type="sha">24f8252f3dd041e37e7c3feb2d57e02b4422d316</open-checksum>
76 support also extension suseinfo format
78 <expire>timestamp</expire>
98 /* normal repomd.xml */
119 /* !! must be sorted by first column !! */
120 static struct stateswitch stateswitches[] = {
122 { STATE_START, "repomd", STATE_REPOMD, 0 },
123 { STATE_START, "suseinfo", STATE_SUSEINFO, 0 },
124 { STATE_SUSEINFO, "expire", STATE_EXPIRE, 1 },
125 { STATE_SUSEINFO, "products", STATE_PRODUCTS, 0 },
126 { STATE_SUSEINFO, "keywords", STATE_KEYWORDS, 0 },
127 { STATE_PRODUCTS, "id", STATE_PRODUCT, 1 },
128 /* keywords is the suse extension equivalent of
129 tags/content when this one was not yet available.
130 therefore we parse both */
131 { STATE_KEYWORDS, "k", STATE_KEYWORD, 1 },
133 { STATE_REPOMD, "revision", STATE_REVISION, 1 },
134 { STATE_REPOMD, "tags", STATE_TAGS, 0 },
135 { STATE_REPOMD, "data", STATE_DATA, 0 },
137 { STATE_TAGS, "content", STATE_CONTENT, 1 },
138 { STATE_TAGS, "distro", STATE_DISTRO, 1 },
140 { STATE_DATA, "location", STATE_LOCATION, 0 },
141 { STATE_DATA, "checksum", STATE_CHECKSUM, 1 },
142 { STATE_DATA, "timestamp", STATE_TIMESTAMP, 1 },
143 { STATE_DATA, "open-checksum", STATE_OPENCHECKSUM, 1 },
160 struct stateswitch *swtab[NUMSTATES];
161 enum state sbtab[NUMSTATES];
169 static inline const char *
170 find_attr(const char *txt, const char **atts)
172 for (; *atts; atts += 2)
174 if (!strcmp(*atts, txt))
182 startElement(void *userData, const char *name, const char **atts)
184 struct parsedata *pd = userData;
185 /*Pool *pool = pd->pool;*/
186 struct stateswitch *sw;
189 fprintf(stderr, "start: [%d]%s\n", pd->state, name);
191 if (pd->depth != pd->statedepth)
198 if (!pd->swtab[pd->state])
200 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++) /* find name in statetable */
201 if (!strcmp(sw->ename, name))
204 if (sw->from != pd->state)
207 fprintf(stderr, "into unknown: %s (from: %d)\n", name, pd->state);
213 pd->docontent = sw->docontent;
214 pd->statedepth = pd->depth;
220 case STATE_START: break;
225 /* this should be OBSOLETE soon */
226 updstr = find_attr("updates", atts);
229 char *value = strdup(updstr);
230 char *fvalue = value; /* save the first */
233 char *p = strchr(value, ',');
237 repo_add_poolstr_array(pd->repo, SOLVID_META, REPOSITORY_UPDATES, value);
244 case STATE_SUSEINFO: break;
245 case STATE_EXPIRE: break;
246 case STATE_PRODUCTS: break;
247 case STATE_PRODUCT: break;
248 case STATE_KEYWORDS: break;
249 case STATE_KEYWORD: break;
250 case STATE_CONTENT: break;
251 case STATE_REVISION: break;
252 case STATE_DISTRO: break;
253 case STATE_DATA: break;
254 case STATE_LOCATION: break;
255 case STATE_CHECKSUM: break;
256 case STATE_TIMESTAMP: break;
257 case STATE_OPENCHECKSUM: break;
258 case NUMSTATES: break;
265 endElement(void *userData, const char *name)
267 struct parsedata *pd = userData;
268 /* Pool *pool = pd->pool; */
271 fprintf(stderr, "end: %s\n", name);
273 if (pd->depth != pd->statedepth)
277 fprintf(stderr, "back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
286 case STATE_START: break;
288 if (pd->timestamp > 0)
289 repodata_set_num(pd->data, SOLVID_META, REPOSITORY_TIMESTAMP, pd->timestamp);
291 case STATE_DATA: break;
292 case STATE_LOCATION: break;
293 case STATE_CHECKSUM: break;
294 case STATE_OPENCHECKSUM: break;
295 case STATE_TIMESTAMP:
298 * we want to look for the newest timestamp
299 * of all resources to save it as the time
300 * the metadata was generated
302 int timestamp = atoi(pd->content);
303 if (timestamp > pd->timestamp)
304 pd->timestamp = timestamp;
309 int expire = atoi(pd->content);
311 repodata_set_num(pd->data, SOLVID_META, REPOSITORY_EXPIRE, expire);
316 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_PRODUCTS, pd->content);
318 /* repomd.xml content and suseinfo.xml keywords are equivalent */
322 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_KEYWORDS, pd->content);
326 repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_REVISION, pd->content);
328 case STATE_DISTRO: break;
329 case STATE_SUSEINFO: break;
330 case STATE_PRODUCTS: break;
331 case STATE_KEYWORDS: break;
332 case NUMSTATES: break;
337 pd->state = pd->sbtab[pd->state];
345 characterData(void *userData, const XML_Char *s, int len)
347 struct parsedata *pd = userData;
352 l = pd->lcontent + len + 1;
353 if (l > pd->acontent)
355 pd->content = realloc(pd->content, l + 256);
356 pd->acontent = l + 256;
358 c = pd->content + pd->lcontent;
365 #define BUFF_SIZE 8192
368 repo_add_repomdxml(Repo *repo, FILE *fp, int flags)
370 Pool *pool = repo->pool;
375 struct stateswitch *sw;
377 if (!(flags & REPO_REUSE_REPODATA))
378 data = repo_add_repodata(repo, 0);
380 data = repo_last_repodata(repo);
382 memset(&pd, 0, sizeof(pd));
384 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
386 if (!pd.swtab[sw->from])
387 pd.swtab[sw->from] = sw;
388 pd.sbtab[sw->to] = sw->from;
394 pd.content = malloc(256);
397 XML_Parser parser = XML_ParserCreate(NULL);
398 XML_SetUserData(parser, &pd);
399 XML_SetElementHandler(parser, startElement, endElement);
400 XML_SetCharacterDataHandler(parser, characterData);
403 l = fread(buf, 1, sizeof(buf), fp);
404 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
406 fprintf(stderr, "repo_repomdxml: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
412 XML_ParserFree(parser);
414 if (!(flags & REPO_NO_INTERNALIZE))
415 repodata_internalize(data);