2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
16 #include "tools_util.h"
17 #include "repo_rpmmd.h"
19 #include "solv_xmlparser.h"
20 #ifdef ENABLE_COMPLEX_DEPS
21 #include "pool_parserpmrichdep.h"
23 #include "repodata_diskusage.h"
40 /* resobject attributes */
55 /* Novell/SUSE extended attributes */
68 /* pattern attributes */
69 STATE_CATEGORY, /* pattern and patches */
87 /* rpm-md dependencies inside the format tag */
102 STATE_OBSOLETESENTRY,
103 STATE_CONFLICTSENTRY,
104 STATE_RECOMMENDSENTRY,
105 STATE_SUPPLEMENTSENTRY,
118 static struct solv_xmlparser_element stateswitches[] = {
119 /** fake tag used to enclose multiple xml files in one **/
120 { STATE_START, "rpmmd", STATE_START, 0 },
122 /** tags for different package data, just ignore them **/
123 { STATE_START, "patterns", STATE_START, 0 },
124 { STATE_START, "products", STATE_START, 0 },
125 { STATE_START, "metadata", STATE_START, 0 },
126 { STATE_START, "otherdata", STATE_START, 0 },
127 { STATE_START, "filelists", STATE_START, 0 },
128 { STATE_START, "diskusagedata", STATE_START, 0 },
129 { STATE_START, "susedata", STATE_START, 0 },
131 { STATE_START, "product", STATE_SOLVABLE, 0 },
132 { STATE_START, "pattern", STATE_SOLVABLE, 0 },
133 { STATE_START, "patch", STATE_SOLVABLE, 0 },
134 { STATE_START, "package", STATE_SOLVABLE, 0 },
136 { STATE_SOLVABLE, "format", STATE_SOLVABLE, 0 },
138 { STATE_SOLVABLE, "name", STATE_NAME, 1 },
139 { STATE_SOLVABLE, "arch", STATE_ARCH, 1 },
140 { STATE_SOLVABLE, "version", STATE_VERSION, 0 },
142 /* package attributes rpm-md */
143 { STATE_SOLVABLE, "location", STATE_LOCATION, 0 },
144 { STATE_SOLVABLE, "checksum", STATE_CHECKSUM, 1 },
146 /* resobject attributes */
148 { STATE_SOLVABLE, "summary", STATE_SUMMARY, 1 },
149 { STATE_SOLVABLE, "description", STATE_DESCRIPTION, 1 },
150 { STATE_SOLVABLE, "distribution", STATE_DISTRIBUTION, 1 },
151 { STATE_SOLVABLE, "url", STATE_URL, 1 },
152 { STATE_SOLVABLE, "packager", STATE_PACKAGER, 1 },
153 { STATE_SOLVABLE, "vendor", STATE_VENDOR, 1 },
154 { STATE_SOLVABLE, "size", STATE_SIZE, 0 },
155 { STATE_SOLVABLE, "archive-size", STATE_DOWNLOADSIZE, 1 },
156 { STATE_SOLVABLE, "install-time", STATE_INSTALLTIME, 1 },
157 { STATE_SOLVABLE, "install-only", STATE_INSTALLONLY, 1 },
158 { STATE_SOLVABLE, "time", STATE_TIME, 0 },
160 /* extended Novell/SUSE attributes (susedata.xml) */
161 { STATE_SOLVABLE, "eula", STATE_EULA, 1 },
162 { STATE_SOLVABLE, "keyword", STATE_KEYWORD, 1 },
163 { STATE_SOLVABLE, "diskusage", STATE_DISKUSAGE, 0 },
165 /* pattern attribute */
166 { STATE_SOLVABLE, "script", STATE_SCRIPT, 1 },
167 { STATE_SOLVABLE, "icon", STATE_ICON, 1 },
168 { STATE_SOLVABLE, "uservisible", STATE_USERVISIBLE, 1 },
169 { STATE_SOLVABLE, "category", STATE_CATEGORY, 1 },
170 { STATE_SOLVABLE, "order", STATE_ORDER, 1 },
171 { STATE_SOLVABLE, "includes", STATE_INCLUDES, 0 },
172 { STATE_SOLVABLE, "extends", STATE_EXTENDS, 0 },
173 { STATE_SOLVABLE, "default", STATE_DEFAULT, 1 },
174 { STATE_SOLVABLE, "install-time", STATE_INSTALL_TIME, 1 },
176 /* product attributes */
177 /* note the product type is an attribute */
178 { STATE_SOLVABLE, "release-notes-url", STATE_RELNOTESURL, 1 },
179 { STATE_SOLVABLE, "update-url", STATE_UPDATEURL, 1 },
180 { STATE_SOLVABLE, "optional-url", STATE_OPTIONALURL, 1 },
181 { STATE_SOLVABLE, "flag", STATE_FLAG, 1 },
183 { STATE_SOLVABLE, "rpm:vendor", STATE_VENDOR, 1 },
184 { STATE_SOLVABLE, "rpm:group", STATE_RPM_GROUP, 1 },
185 { STATE_SOLVABLE, "rpm:license", STATE_RPM_LICENSE, 1 },
187 /* rpm-md dependencies */
188 { STATE_SOLVABLE, "rpm:provides", STATE_PROVIDES, 0 },
189 { STATE_SOLVABLE, "rpm:requires", STATE_REQUIRES, 0 },
190 { STATE_SOLVABLE, "rpm:obsoletes", STATE_OBSOLETES, 0 },
191 { STATE_SOLVABLE, "rpm:conflicts", STATE_CONFLICTS, 0 },
192 { STATE_SOLVABLE, "rpm:recommends", STATE_RECOMMENDS , 0 },
193 { STATE_SOLVABLE, "rpm:supplements", STATE_SUPPLEMENTS, 0 },
194 { STATE_SOLVABLE, "rpm:suggests", STATE_SUGGESTS, 0 },
195 { STATE_SOLVABLE, "rpm:enhances", STATE_ENHANCES, 0 },
196 { STATE_SOLVABLE, "rpm:freshens", STATE_FRESHENS, 0 },
197 { STATE_SOLVABLE, "rpm:sourcerpm", STATE_SOURCERPM, 1 },
198 { STATE_SOLVABLE, "rpm:header-range", STATE_HEADERRANGE, 0 },
199 { STATE_SOLVABLE, "file", STATE_FILE, 1 },
200 { STATE_SOLVABLE, "changelog", STATE_CHANGELOG, 1 },
202 /* extended Novell/SUSE diskusage attributes (susedata.xml) */
203 { STATE_DISKUSAGE, "dirs", STATE_DIRS, 0 },
204 { STATE_DIRS, "dir", STATE_DIR, 0 },
206 { STATE_PROVIDES, "rpm:entry", STATE_PROVIDESENTRY, 0 },
207 { STATE_REQUIRES, "rpm:entry", STATE_REQUIRESENTRY, 0 },
208 { STATE_OBSOLETES, "rpm:entry", STATE_OBSOLETESENTRY, 0 },
209 { STATE_CONFLICTS, "rpm:entry", STATE_CONFLICTSENTRY, 0 },
210 { STATE_RECOMMENDS, "rpm:entry", STATE_RECOMMENDSENTRY, 0 },
211 { STATE_SUPPLEMENTS, "rpm:entry", STATE_SUPPLEMENTSENTRY, 0 },
212 { STATE_SUGGESTS, "rpm:entry", STATE_SUGGESTSENTRY, 0 },
213 { STATE_ENHANCES, "rpm:entry", STATE_ENHANCESENTRY, 0 },
214 { STATE_FRESHENS, "rpm:entry", STATE_FRESHENSENTRY, 0 },
216 { STATE_INCLUDES, "item", STATE_INCLUDESENTRY, 0 },
217 { STATE_EXTENDS, "item", STATE_EXTENDSENTRY, 0 },
231 struct solv_xmlparser xmlp;
233 /* temporal to store attribute tag language */
238 const char *language; /* default language */
239 Id langcache[ID_NUM_INTERNAL]; /* cache for the default language */
247 int extending; /* are we extending an existing solvable? */
248 int first; /* first solvable we added */
249 int cshash_filled; /* hash is filled with data */
251 Hashtable cshash; /* checksum hash -> offset into csdata */
252 Hashval cshashm; /* hash mask */
253 int ncshash; /* entries used */
254 unsigned char *csdata; /* [len, checksum, id] */
255 int ncsdata; /* used bytes */
259 langtag(struct parsedata *pd, Id tag, const char *language)
263 if (!language[0] || !strcmp(language, "en"))
265 return pool_id2langid(pd->pool, tag, language, 1);
269 if (tag >= ID_NUM_INTERNAL)
270 return pool_id2langid(pd->pool, tag, pd->language, 1);
271 if (!pd->langcache[tag])
272 pd->langcache[tag] = pool_id2langid(pd->pool, tag, pd->language, 1);
273 return pd->langcache[tag];
278 * parse 'epoch', 'ver' and 'rel', return evr Id
283 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
285 const char *e, *v, *r, *v2;
290 for (; *atts; atts += 2)
292 if (!strcmp(*atts, "epoch"))
294 else if (!strcmp(*atts, "ver"))
296 else if (!strcmp(*atts, "rel"))
299 if (e && (!*e || !strcmp(e, "0")))
303 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
305 if (v2 > v && *v2 == ':')
315 c = space = solv_xmlparser_contentspace(&pd->xmlp, l);
337 fprintf(stderr, "evr: %s\n", space);
339 return pool_str2id(pool, space, 1);
344 * dependency relations
347 static char *flagtab[] = {
359 * parse attributes to reldep Id
364 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts, int isreq)
367 const char *n, *f, *k;
371 marker = isreq ? -SOLVABLE_PREREQMARKER : 0;
372 for (a = atts; *a; a += 2)
374 if (!strcmp(*a, "name"))
376 else if (!strcmp(*a, "flags"))
378 else if (!strcmp(*a, "kind"))
380 else if (isreq && !strcmp(*a, "pre") && a[1][0] == '1')
381 marker = SOLVABLE_PREREQMARKER;
385 if (k && !strcmp(k, "package"))
389 int l = strlen(k) + 1 + strlen(n) + 1;
390 char *space = solv_xmlparser_contentspace(&pd->xmlp, l);
391 sprintf(space, "%s:%s", k, n);
392 id = pool_str2id(pool, space, 1);
394 #ifdef ENABLE_COMPLEX_DEPS
395 else if (!f && n[0] == '(')
397 id = pool_parserpmrichdep(pool, n);
403 id = pool_str2id(pool, (char *)n, 1);
406 Id evr = makeevr_atts(pool, pd, atts);
408 for (flags = 0; flags < 6; flags++)
409 if (!strcmp(f, flagtab[flags]))
411 flags = flags < 6 ? flags + 1 : 0;
412 id = pool_rel2id(pool, id, evr, flags, 1);
415 fprintf(stderr, "new dep %s\n", pool_dep2str(pool, id));
417 return repo_addid_dep(pd->repo, olddeps, id, marker);
422 * set_description_author
426 set_description_author(Repodata *data, Id handle, char *str, struct parsedata *pd)
432 for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
433 if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
437 /* oh my, found SUSE special author section */
440 while (l > 0 && str[l - 1] == '\n')
443 repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
445 aut = str; /* copy over */
446 while (*p == ' ' || *p == '\n')
459 while (aut != str && aut[-1] == '\n')
463 repodata_set_str(data, handle, SOLVABLE_AUTHORS, str);
466 repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
470 /*-----------------------------------------------*/
471 /* checksum hash functions
473 * used to look up a solvable with the checksum for solvable extension purposes.
478 init_cshash(struct parsedata *pd)
483 free_cshash(struct parsedata *pd)
485 pd->cshash = solv_free(pd->cshash);
488 pd->csdata = solv_free(pd->csdata);
492 static inline Hashval
493 hashkey(const unsigned char *key, int keyl)
495 return key[0] << 24 | key[1] << 16 | key[2] << 8 | key[3];
499 rebuild_cshash(struct parsedata *pd)
503 unsigned char *d, *de;
507 fprintf(stderr, "rebuild cshash with mask 0x%x\n", hm);
509 solv_free(pd->cshash);
510 ht = pd->cshash = (Hashtable)solv_calloc(hm + 1, sizeof(Id));
512 de = d + pd->ncsdata;
515 h = hashkey(d + 1, d[0] + 1) & hm;
516 hh = HASHCHAIN_START;
518 h = HASHCHAIN_NEXT(h, hh, hm);
519 ht[h] = d + 1 - pd->csdata;
520 d += 2 + d[0] + sizeof(Id);
525 put_in_cshash(struct parsedata *pd, const unsigned char *key, int keyl, Id id)
531 if (keyl < 4 || keyl > 256)
535 h = hashkey(key, keyl) & hm;
536 hh = HASHCHAIN_START;
541 unsigned char *d = pd->csdata + ht[h];
542 if (d[-1] == keyl - 1 && !memcmp(key, d, keyl))
543 return; /* XXX: first id wins... */
544 h = HASHCHAIN_NEXT(h, hh, hm);
547 /* a new entry. put in csdata */
548 pd->csdata = solv_extend(pd->csdata, pd->ncsdata, 1 + keyl + sizeof(Id), 1, 4095);
549 d = pd->csdata + pd->ncsdata;
551 memcpy(d + 1, key, keyl);
552 memcpy(d + 1 + keyl, &id, sizeof(Id));
553 pd->ncsdata += 1 + keyl + sizeof(Id);
554 if ((Hashval)++pd->ncshash * 2 > hm)
556 pd->cshashm = pd->cshashm ? (2 * pd->cshashm + 1) : 4095;
560 ht[h] = pd->ncsdata - (keyl + sizeof(Id));
564 lookup_cshash(struct parsedata *pd, const unsigned char *key, int keyl)
569 if (keyl < 4 || keyl > 256)
575 h = hashkey(key, keyl) & hm;
576 hh = HASHCHAIN_START;
579 unsigned char *d = pd->csdata + ht[h];
580 if (d[-1] == keyl - 1 && !memcmp(key, d, keyl))
583 memcpy(&id, d + keyl, sizeof(Id));
586 h = HASHCHAIN_NEXT(h, hh, hm);
592 fill_cshash_from_repo(struct parsedata *pd)
595 /* setup join data */
596 dataiterator_init(&di, pd->pool, pd->repo, 0, SOLVABLE_CHECKSUM, 0, 0);
597 while (dataiterator_step(&di))
598 put_in_cshash(pd, (const unsigned char *)di.kv.str, solv_chksum_len(di.key->type), di.solvid);
599 dataiterator_free(&di);
603 fill_cshash_from_new_solvables(struct parsedata *pd)
605 Pool *pool = pd->pool;
607 unsigned const char *cs;
610 for (i = pd->first; i < pool->nsolvables; i++)
612 if (pool->solvables[i].repo != pd->repo)
614 cs = repodata_lookup_bin_checksum_uninternalized(pd->data, i, SOLVABLE_CHECKSUM, &cstype);
616 put_in_cshash(pd, cs, solv_chksum_len(cstype), i);
620 /*-----------------------------------------------*/
628 startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts)
630 struct parsedata *pd = xmlp->userdata;
631 Pool *pool = pd->pool;
632 Solvable *s = pd->solvable;
633 Id handle = pd->handle;
637 if (!s && state != STATE_SOLVABLE)
644 if (name[2] == 't' && name[3] == 't')
645 pd->kind = "pattern";
646 else if (name[1] == 'r')
647 pd->kind = "product";
648 else if (name[2] == 't' && name[3] == 'c')
651 /* to support extension metadata files like others.xml which
652 have the following structure:
654 <otherdata xmlns="http://linux.duke.edu/metadata/other"
656 <package pkgid="b78f8664cd90efe42e09a345e272997ef1b53c18"
657 name="zaptel-kmp-default"
658 arch="i586"><version epoch="0"
659 ver="1.2.10_2.6.22_rc4_git6_2" rel="70"/>
662 we need to check if the pkgid is there and if it matches
663 an already seen package, that means we don't need to create
664 a new solvable but just append the attributes to the existing
668 if ((pkgid = solv_xmlparser_find_attr("pkgid", atts)) != NULL)
670 unsigned char chk[256];
672 const char *str = pkgid;
673 if (!pd->cshash_filled)
675 pd->cshash_filled = 1;
676 fill_cshash_from_new_solvables(pd);
679 /* convert into bin checksum */
680 l = solv_hex2bin(&str, chk, sizeof(chk));
681 /* look at the checksum cache */
682 if (l >= 4 && !pkgid[2 * l])
683 handle = lookup_cshash(pd, chk, l);
685 fprintf(stderr, "Lookup %s -> %d\n", pkgid, handle);
689 pool_debug(pool, SOLV_WARN, "the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
698 /* this is a new package */
699 handle = repo_add_solvable(pd->repo);
705 pd->solvable = pool_id2solvable(pool, handle);
706 if (pd->kind && pd->kind[1] == 'r')
708 /* products can have a type */
709 const char *type = solv_xmlparser_find_attr("type", atts);
711 repodata_set_str(pd->data, handle, PRODUCT_TYPE, type);
714 fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
719 if (pd->extending && s->evr)
720 break; /* ignore version tag repetition in extend data */
721 s->evr = makeevr_atts(pool, pd, atts);
726 case STATE_PROVIDESENTRY:
727 s->provides = adddep(pool, pd, s->provides, atts, 0);
732 case STATE_REQUIRESENTRY:
733 s->requires = adddep(pool, pd, s->requires, atts, 1);
735 case STATE_OBSOLETES:
738 case STATE_OBSOLETESENTRY:
739 s->obsoletes = adddep(pool, pd, s->obsoletes, atts, 0);
741 case STATE_CONFLICTS:
744 case STATE_CONFLICTSENTRY:
745 s->conflicts = adddep(pool, pd, s->conflicts, atts, 0);
747 case STATE_RECOMMENDS:
750 case STATE_RECOMMENDSENTRY:
751 s->recommends = adddep(pool, pd, s->recommends, atts, 0);
753 case STATE_SUPPLEMENTS:
756 case STATE_SUPPLEMENTSENTRY:
757 s->supplements = adddep(pool, pd, s->supplements, atts, 0);
762 case STATE_SUGGESTSENTRY:
763 s->suggests = adddep(pool, pd, s->suggests, atts, 0);
768 case STATE_ENHANCESENTRY:
769 s->enhances = adddep(pool, pd, s->enhances, atts, 0);
774 case STATE_FRESHENSENTRY:
775 pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
780 case STATE_DESCRIPTION:
781 pd->tmplang = join_dup(&pd->jd, solv_xmlparser_find_attr("lang", atts));
783 case STATE_USERVISIBLE:
784 repodata_set_void(pd->data, handle, SOLVABLE_ISVISIBLE);
786 case STATE_INCLUDESENTRY:
787 str = solv_xmlparser_find_attr("pattern", atts);
789 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_INCLUDES, join2(&pd->jd, "pattern", ":", str));
791 case STATE_EXTENDSENTRY:
792 str = solv_xmlparser_find_attr("pattern", atts);
794 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_EXTENDS, join2(&pd->jd, "pattern", ":", str));
797 str = solv_xmlparser_find_attr("href", atts);
801 const char *base = solv_xmlparser_find_attr("xml:base", atts);
802 if (base && !strncmp(base, "media:", 6))
804 /* check for the media number in the fragment */
805 int l = strlen(base);
806 while (l && base[l - 1] >= '0' && base[l - 1] <= '9')
808 if (l && base[l - 1] == '#' && base[l])
809 medianr = atoi(base + l);
811 repodata_set_location(pd->data, handle, medianr, 0, str);
813 repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIABASE, base);
817 str = solv_xmlparser_find_attr("type", atts);
818 pd->chksumtype = str && *str ? solv_chksum_str2type(str) : 0;
820 pd->ret = pool_error(pool, -1, "line %d: unknown checksum type: %s", solv_xmlparser_lineno(xmlp), str ? str : "NULL");
825 str = solv_xmlparser_find_attr("build", atts);
826 if (str && (t = atoi(str)) != 0)
827 repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, t);
831 if ((str = solv_xmlparser_find_attr("installed", atts)) != 0)
832 repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, strtoull(str, 0, 10));
833 if ((str = solv_xmlparser_find_attr("package", atts)) != 0)
834 repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, strtoull(str, 0, 10));
836 case STATE_HEADERRANGE:
839 str = solv_xmlparser_find_attr("end", atts);
840 if (str && (end = atoi(str)) != 0)
841 repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
847 <dir name="/" size="56" count="11"/>
848 <dir name="usr/" size="56" count="11"/>
849 <dir name="usr/bin/" size="38" count="10"/>
850 <dir name="usr/share/" size="18" count="1"/>
851 <dir name="usr/share/doc/" size="18" count="1"/>
855 case STATE_DISKUSAGE:
857 /* Really, do nothing, wait for <dir> tag */
862 long filesz = 0, filenum = 0;
865 if ((str = solv_xmlparser_find_attr("name", atts)) == 0)
867 pd->ret = pool_error(pool, -1, "<dir .../> tag without 'name' attribute");
872 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
876 int l = strlen(str) + 2;
877 char *space = solv_xmlparser_contentspace(xmlp, l);
879 memcpy(space + 1, str, l - 1);
883 did = repodata_str2dir(pd->data, str, 1);
884 if ((str = solv_xmlparser_find_attr("size", atts)) != 0)
885 filesz = strtol(str, 0, 0);
886 if ((str = solv_xmlparser_find_attr("count", atts)) != 0)
887 filenum = strtol(str, 0, 0);
888 if (filesz || filenum)
890 queue_push(&pd->diskusageq, did);
891 queue_push2(&pd->diskusageq, filesz, filenum);
895 case STATE_CHANGELOG:
896 pd->changelog_handle = repodata_new_handle(pd->data);
897 if ((str = solv_xmlparser_find_attr("date", atts)) != 0)
898 repodata_set_num(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TIME, strtoull(str, 0, 10));
899 if ((str = solv_xmlparser_find_attr("author", atts)) != 0)
900 repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_AUTHOR, str);
913 endElement(struct solv_xmlparser *xmlp, int state, char *content)
915 struct parsedata *pd = xmlp->userdata;
916 Pool *pool = pd->pool;
917 Solvable *s = pd->solvable;
918 Repo *repo = pd->repo;
919 Id handle = pd->handle;
934 if (pd->kind && !s->name) /* add namespace in case of NULL name */
935 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", 0), 1);
937 s->arch = ARCH_NOARCH;
939 s->evr = ID_EMPTY; /* some patterns have this */
940 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
941 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
942 repo_rewrite_suse_deps(s, pd->freshens);
949 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", content), 1);
951 s->name = pool_str2id(pool, content, 1);
954 s->arch = pool_str2id(pool, content, 1);
957 s->vendor = pool_str2id(pool, content, 1);
959 case STATE_RPM_GROUP:
960 repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, content);
962 case STATE_RPM_LICENSE:
963 repodata_set_poolstr(pd->data, handle, SOLVABLE_LICENSE, content);
967 unsigned char chk[256];
968 int l = solv_chksum_len(pd->chksumtype);
969 const char *str = content;
970 if (!l || l > sizeof(chk))
972 if (solv_hex2bin(&str, chk, l) != l || content[2 * l])
974 pd->ret = pool_error(pool, -1, "line %u: invalid %s checksum", solv_xmlparser_lineno(xmlp), solv_chksum_type2str(pd->chksumtype));
977 repodata_set_bin_checksum(pd->data, handle, SOLVABLE_CHECKSUM, pd->chksumtype, chk);
978 /* we save the checksum to solvable id relationship for extending metadata */
979 if (pd->cshash_filled)
980 put_in_cshash(pd, chk, l, s - pool->solvables);
984 if ((p = strrchr(content, '/')) != 0)
987 if (pd->lastdir && !strcmp(pd->lastdirstr, content))
994 if (l + 1 > pd->lastdirstrl) /* + 1 for the possible leading / we need to insert */
996 pd->lastdirstrl = l + 128;
997 pd->lastdirstr = solv_realloc(pd->lastdirstr, pd->lastdirstrl);
999 if (content[0] != '/')
1001 pd->lastdirstr[0] = '/';
1002 memcpy(pd->lastdirstr + 1, content, l);
1003 id = repodata_str2dir(pd->data, pd->lastdirstr, 1);
1006 id = repodata_str2dir(pd->data, content, 1);
1008 memcpy(pd->lastdirstr, content, l);
1014 id = repodata_str2dir(pd->data, "/", 1);
1016 repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
1019 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_SUMMARY, pd->tmplang), content);
1021 case STATE_DESCRIPTION:
1022 set_description_author(pd->data, handle, content, pd);
1024 case STATE_CATEGORY:
1025 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_CATEGORY, pd->tmplang), content);
1027 case STATE_DISTRIBUTION:
1028 repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, content);
1032 repodata_set_str(pd->data, handle, SOLVABLE_URL, content);
1034 case STATE_PACKAGER:
1036 repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, content);
1038 case STATE_SOURCERPM:
1040 repodata_set_sourcepkg(pd->data, handle, content);
1042 case STATE_RELNOTESURL:
1045 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, content);
1046 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "releasenotes", 1));
1049 case STATE_UPDATEURL:
1052 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, content);
1053 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "update", 1));
1056 case STATE_OPTIONALURL:
1059 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, content);
1060 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "optional", 1));
1065 repodata_add_poolstr_array(pd->data, handle, PRODUCT_FLAGS, content);
1069 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->tmplang), content);
1073 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_KEYWORDS, content);
1075 case STATE_DISKUSAGE:
1076 if (pd->diskusageq.count)
1077 repodata_add_diskusage(pd->data, handle, &pd->diskusageq);
1081 repodata_set_str(pd->data, handle, SOLVABLE_ORDER, content);
1083 case STATE_CHANGELOG:
1084 repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TEXT, content);
1085 repodata_add_flexarray(pd->data, handle, SOLVABLE_CHANGELOG, pd->changelog_handle);
1086 pd->changelog_handle = 0;
1094 errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
1096 struct parsedata *pd = xmlp->userdata;
1097 pd->ret = pool_error(pd->pool, -1, "repo_rpmmd: %s at line %u:%u", errstr, line, column);
1101 /*-----------------------------------------------*/
1105 * parse rpm-md metadata (primary, others)
1110 repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
1112 Pool *pool = repo->pool;
1113 struct parsedata pd;
1117 now = solv_timems(0);
1118 data = repo_add_repodata(repo, flags);
1120 memset(&pd, 0, sizeof(pd));
1126 pd.language = language && *language && strcmp(language, "en") != 0 ? language : 0;
1127 queue_init(&pd.diskusageq);
1130 if ((flags & REPO_EXTEND_SOLVABLES) != 0)
1132 /* setup join data */
1133 pd.cshash_filled = 1;
1134 fill_cshash_from_repo(&pd);
1137 solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
1138 solv_xmlparser_parse(&pd.xmlp, fp);
1139 solv_xmlparser_free(&pd.xmlp);
1141 solv_free(pd.lastdirstr);
1142 join_freemem(&pd.jd);
1144 repodata_free_dircache(data);
1145 queue_free(&pd.diskusageq);
1147 if (!(flags & REPO_NO_INTERNALIZE))
1148 repodata_internalize(data);
1149 POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", solv_timems(now));
1150 POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1151 POOL_DEBUG(SOLV_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", repodata_memused(data)/1024, repo->idarraysize / (int)(1024/sizeof(Id)));