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;
610 for (i = pd->first; i < pool->nsolvables; i++)
612 if (pool->solvables[i].repo != pd->repo)
614 if ((key = repodata_lookup_kv_uninternalized(pd->data, i, SOLVABLE_CHECKSUM, &kv)) == 0)
616 if ((l = solv_chksum_len(key->type)) != 0)
617 put_in_cshash(pd, (const unsigned char *)kv.str, l, i);
621 /*-----------------------------------------------*/
629 startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts)
631 struct parsedata *pd = xmlp->userdata;
632 Pool *pool = pd->pool;
633 Solvable *s = pd->solvable;
634 Id handle = pd->handle;
638 if (!s && state != STATE_SOLVABLE)
645 if (name[2] == 't' && name[3] == 't')
646 pd->kind = "pattern";
647 else if (name[1] == 'r')
648 pd->kind = "product";
649 else if (name[2] == 't' && name[3] == 'c')
652 /* to support extension metadata files like others.xml which
653 have the following structure:
655 <otherdata xmlns="http://linux.duke.edu/metadata/other"
657 <package pkgid="b78f8664cd90efe42e09a345e272997ef1b53c18"
658 name="zaptel-kmp-default"
659 arch="i586"><version epoch="0"
660 ver="1.2.10_2.6.22_rc4_git6_2" rel="70"/>
663 we need to check if the pkgid is there and if it matches
664 an already seen package, that means we don't need to create
665 a new solvable but just append the attributes to the existing
669 if ((pkgid = solv_xmlparser_find_attr("pkgid", atts)) != NULL)
671 unsigned char chk[256];
673 const char *str = pkgid;
674 if (!pd->cshash_filled)
676 pd->cshash_filled = 1;
677 fill_cshash_from_new_solvables(pd);
680 /* convert into bin checksum */
681 l = solv_hex2bin(&str, chk, sizeof(chk));
682 /* look at the checksum cache */
683 if (l >= 4 && !pkgid[2 * l])
684 handle = lookup_cshash(pd, chk, l);
686 fprintf(stderr, "Lookup %s -> %d\n", pkgid, handle);
690 pool_debug(pool, SOLV_WARN, "the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
699 /* this is a new package */
700 handle = repo_add_solvable(pd->repo);
706 pd->solvable = pool_id2solvable(pool, handle);
707 if (pd->kind && pd->kind[1] == 'r')
709 /* products can have a type */
710 const char *type = solv_xmlparser_find_attr("type", atts);
712 repodata_set_str(pd->data, handle, PRODUCT_TYPE, type);
715 fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
720 if (pd->extending && s->evr)
721 break; /* ignore version tag repetition in extend data */
722 s->evr = makeevr_atts(pool, pd, atts);
727 case STATE_PROVIDESENTRY:
728 s->provides = adddep(pool, pd, s->provides, atts, 0);
733 case STATE_REQUIRESENTRY:
734 s->requires = adddep(pool, pd, s->requires, atts, 1);
736 case STATE_OBSOLETES:
739 case STATE_OBSOLETESENTRY:
740 s->obsoletes = adddep(pool, pd, s->obsoletes, atts, 0);
742 case STATE_CONFLICTS:
745 case STATE_CONFLICTSENTRY:
746 s->conflicts = adddep(pool, pd, s->conflicts, atts, 0);
748 case STATE_RECOMMENDS:
751 case STATE_RECOMMENDSENTRY:
752 s->recommends = adddep(pool, pd, s->recommends, atts, 0);
754 case STATE_SUPPLEMENTS:
757 case STATE_SUPPLEMENTSENTRY:
758 s->supplements = adddep(pool, pd, s->supplements, atts, 0);
763 case STATE_SUGGESTSENTRY:
764 s->suggests = adddep(pool, pd, s->suggests, atts, 0);
769 case STATE_ENHANCESENTRY:
770 s->enhances = adddep(pool, pd, s->enhances, atts, 0);
775 case STATE_FRESHENSENTRY:
776 pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
781 case STATE_DESCRIPTION:
782 pd->tmplang = join_dup(&pd->jd, solv_xmlparser_find_attr("lang", atts));
784 case STATE_USERVISIBLE:
785 repodata_set_void(pd->data, handle, SOLVABLE_ISVISIBLE);
787 case STATE_INCLUDESENTRY:
788 str = solv_xmlparser_find_attr("pattern", atts);
790 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_INCLUDES, join2(&pd->jd, "pattern", ":", str));
792 case STATE_EXTENDSENTRY:
793 str = solv_xmlparser_find_attr("pattern", atts);
795 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_EXTENDS, join2(&pd->jd, "pattern", ":", str));
798 str = solv_xmlparser_find_attr("href", atts);
802 const char *base = solv_xmlparser_find_attr("xml:base", atts);
803 if (base && !strncmp(base, "media:", 6))
805 /* check for the media number in the fragment */
806 int l = strlen(base);
807 while (l && base[l - 1] >= '0' && base[l - 1] <= '9')
809 if (l && base[l - 1] == '#' && base[l])
810 medianr = atoi(base + l);
812 repodata_set_location(pd->data, handle, medianr, 0, str);
814 repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIABASE, base);
818 str = solv_xmlparser_find_attr("type", atts);
819 pd->chksumtype = str && *str ? solv_chksum_str2type(str) : 0;
821 pd->ret = pool_error(pool, -1, "line %d: unknown checksum type: %s", solv_xmlparser_lineno(xmlp), str ? str : "NULL");
826 str = solv_xmlparser_find_attr("build", atts);
827 if (str && (t = atoi(str)) != 0)
828 repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, t);
832 if ((str = solv_xmlparser_find_attr("installed", atts)) != 0)
833 repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, strtoull(str, 0, 10));
834 if ((str = solv_xmlparser_find_attr("package", atts)) != 0)
835 repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, strtoull(str, 0, 10));
837 case STATE_HEADERRANGE:
840 str = solv_xmlparser_find_attr("end", atts);
841 if (str && (end = atoi(str)) != 0)
842 repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
848 <dir name="/" size="56" count="11"/>
849 <dir name="usr/" size="56" count="11"/>
850 <dir name="usr/bin/" size="38" count="10"/>
851 <dir name="usr/share/" size="18" count="1"/>
852 <dir name="usr/share/doc/" size="18" count="1"/>
856 case STATE_DISKUSAGE:
858 /* Really, do nothing, wait for <dir> tag */
863 long filesz = 0, filenum = 0;
866 if ((str = solv_xmlparser_find_attr("name", atts)) == 0)
868 pd->ret = pool_error(pool, -1, "<dir .../> tag without 'name' attribute");
873 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
877 int l = strlen(str) + 2;
878 char *space = solv_xmlparser_contentspace(xmlp, l);
880 memcpy(space + 1, str, l - 1);
884 did = repodata_str2dir(pd->data, str, 1);
885 if ((str = solv_xmlparser_find_attr("size", atts)) != 0)
886 filesz = strtol(str, 0, 0);
887 if ((str = solv_xmlparser_find_attr("count", atts)) != 0)
888 filenum = strtol(str, 0, 0);
889 if (filesz || filenum)
891 queue_push(&pd->diskusageq, did);
892 queue_push2(&pd->diskusageq, filesz, filenum);
896 case STATE_CHANGELOG:
897 pd->changelog_handle = repodata_new_handle(pd->data);
898 if ((str = solv_xmlparser_find_attr("date", atts)) != 0)
899 repodata_set_num(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TIME, strtoull(str, 0, 10));
900 if ((str = solv_xmlparser_find_attr("author", atts)) != 0)
901 repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_AUTHOR, str);
914 endElement(struct solv_xmlparser *xmlp, int state, char *content)
916 struct parsedata *pd = xmlp->userdata;
917 Pool *pool = pd->pool;
918 Solvable *s = pd->solvable;
919 Repo *repo = pd->repo;
920 Id handle = pd->handle;
935 if (pd->kind && !s->name) /* add namespace in case of NULL name */
936 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", 0), 1);
938 s->arch = ARCH_NOARCH;
940 s->evr = ID_EMPTY; /* some patterns have this */
941 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
942 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
943 repo_rewrite_suse_deps(s, pd->freshens);
950 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", content), 1);
952 s->name = pool_str2id(pool, content, 1);
955 s->arch = pool_str2id(pool, content, 1);
958 s->vendor = pool_str2id(pool, content, 1);
960 case STATE_RPM_GROUP:
961 repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, content);
963 case STATE_RPM_LICENSE:
964 repodata_set_poolstr(pd->data, handle, SOLVABLE_LICENSE, content);
968 unsigned char chk[256];
969 int l = solv_chksum_len(pd->chksumtype);
970 const char *str = content;
971 if (!l || l > sizeof(chk))
973 if (solv_hex2bin(&str, chk, l) != l || content[2 * l])
975 pd->ret = pool_error(pool, -1, "line %u: invalid %s checksum", solv_xmlparser_lineno(xmlp), solv_chksum_type2str(pd->chksumtype));
978 repodata_set_bin_checksum(pd->data, handle, SOLVABLE_CHECKSUM, pd->chksumtype, chk);
979 /* we save the checksum to solvable id relationship for extending metadata */
980 if (pd->cshash_filled)
981 put_in_cshash(pd, chk, l, s - pool->solvables);
985 if ((p = strrchr(content, '/')) != 0)
988 if (pd->lastdir && !strcmp(pd->lastdirstr, content))
995 if (l + 1 > pd->lastdirstrl) /* + 1 for the possible leading / we need to insert */
997 pd->lastdirstrl = l + 128;
998 pd->lastdirstr = solv_realloc(pd->lastdirstr, pd->lastdirstrl);
1000 if (content[0] != '/')
1002 pd->lastdirstr[0] = '/';
1003 memcpy(pd->lastdirstr + 1, content, l);
1004 id = repodata_str2dir(pd->data, pd->lastdirstr, 1);
1007 id = repodata_str2dir(pd->data, content, 1);
1009 memcpy(pd->lastdirstr, content, l);
1015 id = repodata_str2dir(pd->data, "/", 1);
1017 repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
1020 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_SUMMARY, pd->tmplang), content);
1022 case STATE_DESCRIPTION:
1023 set_description_author(pd->data, handle, content, pd);
1025 case STATE_CATEGORY:
1026 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_CATEGORY, pd->tmplang), content);
1028 case STATE_DISTRIBUTION:
1029 repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, content);
1033 repodata_set_str(pd->data, handle, SOLVABLE_URL, content);
1035 case STATE_PACKAGER:
1037 repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, content);
1039 case STATE_SOURCERPM:
1041 repodata_set_sourcepkg(pd->data, handle, content);
1043 case STATE_RELNOTESURL:
1046 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, content);
1047 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "releasenotes", 1));
1050 case STATE_UPDATEURL:
1053 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, content);
1054 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "update", 1));
1057 case STATE_OPTIONALURL:
1060 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, content);
1061 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "optional", 1));
1066 repodata_add_poolstr_array(pd->data, handle, PRODUCT_FLAGS, content);
1070 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->tmplang), content);
1074 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_KEYWORDS, content);
1076 case STATE_DISKUSAGE:
1077 if (pd->diskusageq.count)
1078 repodata_add_diskusage(pd->data, handle, &pd->diskusageq);
1082 repodata_set_str(pd->data, handle, SOLVABLE_ORDER, content);
1084 case STATE_CHANGELOG:
1085 repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TEXT, content);
1086 repodata_add_flexarray(pd->data, handle, SOLVABLE_CHANGELOG, pd->changelog_handle);
1087 pd->changelog_handle = 0;
1095 /*-----------------------------------------------*/
1099 * parse rpm-md metadata (primary, others)
1104 repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
1106 Pool *pool = repo->pool;
1107 struct parsedata pd;
1111 now = solv_timems(0);
1112 data = repo_add_repodata(repo, flags);
1114 memset(&pd, 0, sizeof(pd));
1120 pd.language = language && *language && strcmp(language, "en") != 0 ? language : 0;
1121 queue_init(&pd.diskusageq);
1124 if ((flags & REPO_EXTEND_SOLVABLES) != 0)
1126 /* setup join data */
1127 pd.cshash_filled = 1;
1128 fill_cshash_from_repo(&pd);
1131 solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
1132 if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
1133 pd.ret = pool_error(pool, -1, "repo_rpmmd: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
1134 solv_xmlparser_free(&pd.xmlp);
1136 solv_free(pd.lastdirstr);
1137 join_freemem(&pd.jd);
1139 repodata_free_dircache(data);
1140 queue_free(&pd.diskusageq);
1142 if ((flags & REPO_EXTEND_SOLVABLES) != 0)
1144 /* is this a filelist extension? */
1145 if (repodata_has_keyname(data, SOLVABLE_FILELIST))
1146 repodata_set_filelisttype(data, REPODATA_FILELIST_EXTENSION);
1150 /* is this a primary with a filtered filelist? */
1151 if (data->end > data->start)
1153 repodata_set_filelisttype(data, REPODATA_FILELIST_FILTERED);
1154 repodata_set_void(data, SOLVID_META, REPOSITORY_FILTEREDFILELIST);
1158 if (!(flags & REPO_NO_INTERNALIZE))
1159 repodata_internalize(data);
1160 POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", solv_timems(now));
1161 POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1162 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)));