2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
19 #include "tools_util.h"
20 #include "repo_rpmmd.h"
39 /* resobject attributes */
54 /* Novell/SUSE extended attributes */
67 /* pattern attributes */
68 STATE_CATEGORY, /* pattern and patches */
82 STATE_DISTNAME, /* obsolete */
83 STATE_DISTEDITION, /* obsolete */
91 /* rpm-md dependencies inside the
107 STATE_OBSOLETESENTRY,
108 STATE_CONFLICTSENTRY,
109 STATE_RECOMMENDSENTRY,
110 STATE_SUPPLEMENTSENTRY,
128 static struct stateswitch stateswitches[] = {
129 /** fake tag used to enclose 2 different xml files in one **/
130 { STATE_START, "rpmmd", STATE_START, 0 },
132 /** tags for different package data, we just ignore the tag **/
133 { STATE_START, "metadata", STATE_START, 0 },
134 { STATE_START, "otherdata", STATE_START, 0 },
135 { STATE_START, "filelists", STATE_START, 0 },
136 { STATE_START, "diskusagedata", STATE_START, 0 },
137 { STATE_START, "susedata", STATE_START, 0 },
139 { STATE_START, "product", STATE_SOLVABLE, 0 },
140 { STATE_START, "pattern", STATE_SOLVABLE, 0 },
141 { STATE_START, "patch", STATE_SOLVABLE, 0 },
142 { STATE_START, "package", STATE_SOLVABLE, 0 },
144 { STATE_SOLVABLE, "name", STATE_NAME, 1 },
145 { STATE_SOLVABLE, "arch", STATE_ARCH, 1 },
146 { STATE_SOLVABLE, "version", STATE_VERSION, 0 },
148 /* package attributes rpm-md */
149 { STATE_SOLVABLE, "location", STATE_LOCATION, 0 },
150 { STATE_SOLVABLE, "checksum", STATE_CHECKSUM, 1 },
152 /* resobject attributes */
154 { STATE_SOLVABLE, "summary", STATE_SUMMARY, 1 },
155 { STATE_SOLVABLE, "description", STATE_DESCRIPTION, 1 },
156 { STATE_SOLVABLE, "distribution", STATE_DISTRIBUTION, 1 },
157 { STATE_SOLVABLE, "url", STATE_URL, 1 },
158 { STATE_SOLVABLE, "packager", STATE_PACKAGER, 1 },
159 { STATE_SOLVABLE, "vendor", STATE_VENDOR, 1 },
160 { STATE_SOLVABLE, "size", STATE_SIZE, 0 },
161 { STATE_SOLVABLE, "archive-size", STATE_DOWNLOADSIZE, 1 },
162 { STATE_SOLVABLE, "install-time", STATE_INSTALLTIME, 1 },
163 { STATE_SOLVABLE, "install-only", STATE_INSTALLONLY, 1 },
164 { STATE_SOLVABLE, "time", STATE_TIME, 0 },
166 /* extended Novell/SUSE attributes (susedata.xml) */
167 { STATE_SOLVABLE, "eula", STATE_EULA, 1 },
168 { STATE_SOLVABLE, "keyword", STATE_KEYWORD, 1 },
169 { STATE_SOLVABLE, "diskusage", STATE_DISKUSAGE, 0 },
171 /* pattern attribute */
172 { STATE_SOLVABLE, "script", STATE_SCRIPT, 1 },
173 { STATE_SOLVABLE, "icon", STATE_ICON, 1 },
174 { STATE_SOLVABLE, "uservisible", STATE_USERVISIBLE, 1 },
175 { STATE_SOLVABLE, "category", STATE_CATEGORY, 1 },
176 { STATE_SOLVABLE, "order", STATE_ORDER, 1 },
177 { STATE_SOLVABLE, "includes", STATE_INCLUDES, 0 },
178 { STATE_SOLVABLE, "extends", STATE_EXTENDS, 0 },
179 { STATE_SOLVABLE, "default", STATE_DEFAULT, 1 },
180 { STATE_SOLVABLE, "install-time", STATE_INSTALL_TIME, 1 },
182 /* product attributes */
183 /* note the product type is an attribute */
184 { STATE_SOLVABLE, "release-notes-url", STATE_RELNOTESURL, 1 },
185 { STATE_SOLVABLE, "update-url", STATE_UPDATEURL, 1 },
186 { STATE_SOLVABLE, "optional-url", STATE_OPTIONALURL, 1 },
187 { STATE_SOLVABLE, "flag", STATE_FLAG, 1 },
189 { STATE_SOLVABLE, "rpm:vendor", STATE_VENDOR, 1 },
190 { STATE_SOLVABLE, "rpm:group", STATE_RPM_GROUP, 1 },
191 { STATE_SOLVABLE, "rpm:license", STATE_RPM_LICENSE, 1 },
193 /* rpm-md dependencies */
194 { STATE_SOLVABLE, "rpm:provides", STATE_PROVIDES, 0 },
195 { STATE_SOLVABLE, "rpm:requires", STATE_REQUIRES, 0 },
196 { STATE_SOLVABLE, "rpm:obsoletes", STATE_OBSOLETES, 0 },
197 { STATE_SOLVABLE, "rpm:conflicts", STATE_CONFLICTS, 0 },
198 { STATE_SOLVABLE, "rpm:recommends", STATE_RECOMMENDS , 0 },
199 { STATE_SOLVABLE, "rpm:supplements", STATE_SUPPLEMENTS, 0 },
200 { STATE_SOLVABLE, "rpm:suggests", STATE_SUGGESTS, 0 },
201 { STATE_SOLVABLE, "rpm:enhances", STATE_ENHANCES, 0 },
202 { STATE_SOLVABLE, "rpm:freshens", STATE_FRESHENS, 0 },
203 { STATE_SOLVABLE, "rpm:sourcerpm", STATE_SOURCERPM, 1 },
204 { STATE_SOLVABLE, "rpm:header-range", STATE_HEADERRANGE, 0 },
205 { STATE_SOLVABLE, "file", STATE_FILE, 1 },
207 /* extended Novell/SUSE diskusage attributes (susedata.xml) */
208 { STATE_DISKUSAGE, "dirs", STATE_DIRS, 0 },
209 { STATE_DIRS, "dir", STATE_DIR, 0 },
211 { STATE_PROVIDES, "rpm:entry", STATE_PROVIDESENTRY, 0 },
212 { STATE_REQUIRES, "rpm:entry", STATE_REQUIRESENTRY, 0 },
213 { STATE_OBSOLETES, "rpm:entry", STATE_OBSOLETESENTRY, 0 },
214 { STATE_CONFLICTS, "rpm:entry", STATE_CONFLICTSENTRY, 0 },
215 { STATE_RECOMMENDS, "rpm:entry", STATE_RECOMMENDSENTRY, 0 },
216 { STATE_SUPPLEMENTS, "rpm:entry", STATE_SUPPLEMENTSENTRY, 0 },
217 { STATE_SUGGESTS, "rpm:entry", STATE_SUGGESTSENTRY, 0 },
218 { STATE_ENHANCES, "rpm:entry", STATE_ENHANCESENTRY, 0 },
219 { STATE_FRESHENS, "rpm:entry", STATE_FRESHENSENTRY, 0 },
221 { STATE_INCLUDES, "item", STATE_INCLUDESENTRY, 0 },
222 { STATE_EXTENDS, "item", STATE_EXTENDSENTRY, 0 },
227 /* maxmum initial size of
228 the checksum cache */
229 #define MAX_CSCACHE 32768
230 #define CSREALLOC_STEP 1024
247 struct stateswitch *swtab[NUMSTATES];
248 enum state sbtab[NUMSTATES];
250 /* temporal to store attribute tag language */
255 Id (*dirs)[3]; /* dirid, size, nfiles */
257 const char *language; /* default language */
258 Id langcache[ID_NUM_INTERNAL]; /* cache for the default language */
264 /** Hash to maps checksums to solv */
266 /** Cache of known checksums to solvable id */
268 /* the current longest index in the table */
273 langtag(struct parsedata *pd, Id tag, const char *language)
277 if (!language[0] || !strcmp(language, "en"))
279 return pool_id2langid(pd->pool, tag, language, 1);
283 if (tag >= ID_NUM_INTERNAL)
284 return pool_id2langid(pd->pool, tag, pd->language, 1);
285 if (!pd->langcache[tag])
286 pd->langcache[tag] = pool_id2langid(pd->pool, tag, pd->language, 1);
287 return pd->langcache[tag];
291 id3_cmp (const void *v1, const void *v2, void *dp)
295 return i1[0] - i2[0];
299 commit_diskusage (struct parsedata *pd, Id handle)
302 Dirpool *dp = &pd->data->dirpool;
303 /* Now sort in dirid order. This ensures that parents come before
306 solv_sort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp, 0);
307 /* Substract leaf numbers from all parents to make the numbers
308 non-cumulative. This must be done post-order (i.e. all leafs
309 adjusted before parents). We ensure this by starting at the end of
310 the array moving to the start, hence seeing leafs before parents. */
311 for (i = pd->ndirs; i--;)
313 Id p = dirpool_parent(dp, pd->dirs[i][0]);
315 for (; p; p = dirpool_parent(dp, p))
318 if (pd->dirs[j][0] == p)
322 if (pd->dirs[j][1] < pd->dirs[i][1])
325 pd->dirs[j][1] -= pd->dirs[i][1];
326 if (pd->dirs[j][2] < pd->dirs[i][2])
329 pd->dirs[j][2] -= pd->dirs[i][2];
332 /* Haven't found this parent in the list, look further if
333 we maybe find the parents parent. */
340 unsigned slen = sizeof (sbuf);
341 for (i = 0; i < pd->ndirs; i++)
343 dir2str (attr, pd->dirs[i][0], &buf, &slen);
344 fprintf (stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf);
349 for (i = 0; i < pd->ndirs; i++)
350 if (pd->dirs[i][1] || pd->dirs[i][2])
352 repodata_add_dirnumnum(pd->data, handle, SOLVABLE_DISKUSAGE, pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2]);
360 * parse 'epoch', 'ver' and 'rel', return evr Id
365 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
367 const char *e, *v, *r, *v2;
372 for (; *atts; atts += 2)
374 if (!strcmp(*atts, "epoch"))
376 else if (!strcmp(*atts, "ver"))
378 else if (!strcmp(*atts, "rel"))
381 if (e && !strcmp(e, "0"))
385 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
387 if (v2 > v && *v2 == ':')
397 if (l > pd->acontent)
399 pd->content = solv_realloc(pd->content, l + 256);
400 pd->acontent = l + 256;
424 fprintf(stderr, "evr: %s\n", pd->content);
426 return pool_str2id(pool, pd->content, 1);
432 * find value for xml attribute
433 * I: txt, name of attribute
434 * I: atts, list of key/value attributes
435 * O: pointer to value of matching key, or NULL
439 static inline const char *
440 find_attr(const char *txt, const char **atts)
442 for (; *atts; atts += 2)
444 if (!strcmp(*atts, txt))
452 * dependency relations
455 static char *flagtab[] = {
467 * parse attributes to reldep Id
472 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts, int isreq)
475 const char *n, *f, *k;
479 marker = isreq ? -SOLVABLE_PREREQMARKER : 0;
480 for (a = atts; *a; a += 2)
482 if (!strcmp(*a, "name"))
484 else if (!strcmp(*a, "flags"))
486 else if (!strcmp(*a, "kind"))
488 else if (isreq && !strcmp(*a, "pre") && a[1][0] == '1')
489 marker = SOLVABLE_PREREQMARKER;
493 if (k && !strcmp(k, "package"))
497 int l = strlen(k) + 1 + strlen(n) + 1;
498 if (l > pd->acontent)
500 pd->content = solv_realloc(pd->content, l + 256);
501 pd->acontent = l + 256;
503 sprintf(pd->content, "%s:%s", k, n);
504 name = pool_str2id(pool, pd->content, 1);
507 name = pool_str2id(pool, (char *)n, 1);
510 Id evr = makeevr_atts(pool, pd, atts);
512 for (flags = 0; flags < 6; flags++)
513 if (!strcmp(f, flagtab[flags]))
515 flags = flags < 6 ? flags + 1 : 0;
516 id = pool_rel2id(pool, name, evr, flags, 1);
521 fprintf(stderr, "new dep %s%s%s\n", pool_id2str(pool, d), id2rel(pool, d), id2evr(pool, d));
523 return repo_addid_dep(pd->repo, olddeps, id, marker);
528 * set_description_author
532 set_description_author(Repodata *data, Id handle, char *str, struct parsedata *pd)
538 for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
539 if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
543 /* oh my, found SUSE special author section */
546 while (l > 0 && str[l - 1] == '\n')
549 repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
551 aut = str; /* copy over */
552 while (*p == ' ' || *p == '\n')
565 while (aut != str && aut[-1] == '\n')
569 repodata_set_str(data, handle, SOLVABLE_AUTHORS, str);
572 repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
582 set_sourcerpm(Repodata *data, Solvable *s, Id handle, const char *sourcerpm)
584 const char *p, *sevr, *sarch, *name, *evr;
587 p = strrchr(sourcerpm, '.');
588 if (!p || strcmp(p, ".rpm") != 0)
591 while (p > sourcerpm && *p != '.')
593 if (*p != '.' || p == sourcerpm)
596 while (p > sourcerpm && *p != '-')
598 if (*p != '-' || p == sourcerpm)
601 while (p > sourcerpm && *p != '-')
603 if (*p != '-' || p == sourcerpm)
606 pool = s->repo->pool;
607 if (!strcmp(sarch, "src.rpm"))
608 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_SRC);
609 else if (!strcmp(sarch, "nosrc.rpm"))
610 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_NOSRC);
612 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, pool_strn2id(pool, sarch, strlen(sarch) - 4, 1));
613 evr = pool_id2str(pool, s->evr);
614 if (evr && !strncmp(sevr, evr, sarch - sevr - 1) && evr[sarch - sevr - 1] == 0)
615 repodata_set_void(data, handle, SOLVABLE_SOURCEEVR);
617 repodata_set_id(data, handle, SOLVABLE_SOURCEEVR, pool_strn2id(pool, sevr, sarch - sevr - 1, 1));
618 name = pool_id2str(pool, s->name);
619 if (name && !strncmp(sourcerpm, name, sevr - sourcerpm - 1) && name[sevr - sourcerpm - 1] == 0)
620 repodata_set_void(data, handle, SOLVABLE_SOURCENAME);
622 repodata_set_id(data, handle, SOLVABLE_SOURCENAME, pool_strn2id(pool, sourcerpm, sevr - sourcerpm - 1, 1));
625 /*-----------------------------------------------*/
635 startElement(void *userData, const char *name, const char **atts)
637 struct parsedata *pd = userData;
638 Pool *pool = pd->pool;
639 Solvable *s = pd->solvable;
640 struct stateswitch *sw;
642 Id handle = pd->handle;
645 /* fprintf(stderr, "into %s, from %d, depth %d, statedepth %d\n", name, pd->state, pd->depth, pd->statedepth); */
647 if (pd->depth != pd->statedepth)
653 if (pd->state == STATE_START && !strcmp(name, "patterns"))
655 if (pd->state == STATE_START && !strcmp(name, "products"))
658 if (pd->state == STATE_START && !strcmp(name, "metadata"))
661 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
665 if (!pd->swtab[pd->state])
667 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++)
668 if (!strcmp(sw->ename, name))
670 if (sw->from != pd->state)
673 fprintf(stderr, "into unknown: %s\n", name);
678 pd->docontent = sw->docontent;
679 pd->statedepth = pd->depth;
683 if (!s && pd->state != STATE_SOLVABLE)
690 if (name[2] == 't' && name[3] == 't')
691 pd->kind = "pattern";
692 else if (name[1] == 'r')
693 pd->kind = "product";
694 else if (name[2] == 't' && name[3] == 'c')
697 /* to support extension metadata files like others.xml which
698 have the following structure:
700 <otherdata xmlns="http://linux.duke.edu/metadata/other"
702 <package pkgid="b78f8664cd90efe42e09a345e272997ef1b53c18"
703 name="zaptel-kmp-default"
704 arch="i586"><version epoch="0"
705 ver="1.2.10_2.6.22_rc4_git6_2" rel="70"/>
708 we need to check if the pkgid is there and if it matches
709 an already seen package, that means we don't need to create
710 a new solvable but just append the attributes to the existing
713 if ((pkgid = find_attr("pkgid", atts)) != NULL)
715 /* look at the checksum cache */
716 Id index = stringpool_str2id(&pd->cspool, pkgid, 0);
717 if (!index || index >= pd->ncscache || !pd->cscache[index])
719 pool_debug(pool, SOLV_WARN, "the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
724 pd->solvable = pool_id2solvable(pool, pd->cscache[index]);
728 /* this is a new package */
729 pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
732 pd->handle = pd->solvable - pool->solvables;
734 fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
739 s->evr = makeevr_atts(pool, pd, atts);
744 case STATE_PROVIDESENTRY:
745 s->provides = adddep(pool, pd, s->provides, atts, 0);
750 case STATE_REQUIRESENTRY:
751 s->requires = adddep(pool, pd, s->requires, atts, 1);
753 case STATE_OBSOLETES:
756 case STATE_OBSOLETESENTRY:
757 s->obsoletes = adddep(pool, pd, s->obsoletes, atts, 0);
759 case STATE_CONFLICTS:
762 case STATE_CONFLICTSENTRY:
763 s->conflicts = adddep(pool, pd, s->conflicts, atts, 0);
765 case STATE_RECOMMENDS:
768 case STATE_RECOMMENDSENTRY:
769 s->recommends = adddep(pool, pd, s->recommends, atts, 0);
771 case STATE_SUPPLEMENTS:
774 case STATE_SUPPLEMENTSENTRY:
775 s->supplements = adddep(pool, pd, s->supplements, atts, 0);
780 case STATE_SUGGESTSENTRY:
781 s->suggests = adddep(pool, pd, s->suggests, atts, 0);
786 case STATE_ENHANCESENTRY:
787 s->enhances = adddep(pool, pd, s->enhances, atts, 0);
792 case STATE_FRESHENSENTRY:
793 pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
798 case STATE_DESCRIPTION:
799 pd->tmplang = join_dup(&pd->jd, find_attr("lang", atts));
801 case STATE_USERVISIBLE:
802 repodata_set_void(pd->data, handle, SOLVABLE_ISVISIBLE);
804 case STATE_INCLUDESENTRY:
806 const char *tmp = find_attr("pattern", atts);
808 repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_INCLUDES, join2(&pd->jd, "pattern", ":", tmp));
811 case STATE_EXTENDSENTRY:
813 const char *tmp = find_attr("pattern", atts);
815 repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_EXTENDS, join2(&pd->jd, "pattern", ":", tmp));
819 str = find_attr("href", atts);
821 repodata_set_location(pd->data, handle, 0, 0, str);
825 const char *tmp = find_attr("type", atts);
826 pd->chksumtype = tmp && *tmp ? solv_chksum_str2type(tmp) : 0;
828 pd->ret = pool_error(pool, -1, "line %d: unknown checksum type: %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), tmp ? tmp: "NULL");
834 str = find_attr("build", atts);
835 if (str && (t = atoi(str)) != 0)
836 repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, t);
841 unsigned long long k;
842 str = find_attr("installed", atts);
843 if (str && (k = strtoull(str, 0, 10)) != 0)
844 repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, k);
845 /* XXX the "package" attribute gives the size of the rpm file,
846 i.e. the download size. Except on packman, there it seems to be
847 something else entirely, it has a value near to the other two
848 values, as if the rpm is uncompressed. */
849 str = find_attr("package", atts);
850 if (str && (k = strtoull(str, 0, 10)) != 0)
851 repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, k);
854 case STATE_HEADERRANGE:
857 str = find_attr("end", atts);
858 if (str && (end = atoi(str)) != 0)
859 repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
865 <dir name="/" size="56" count="11"/>
866 <dir name="usr/" size="56" count="11"/>
867 <dir name="usr/bin/" size="38" count="10"/>
868 <dir name="usr/share/" size="18" count="1"/>
869 <dir name="usr/share/doc/" size="18" count="1"/>
873 case STATE_DISKUSAGE:
875 /* Really, do nothing, wait for <dir> tag */
880 long filesz = 0, filenum = 0;
882 if ((str = find_attr("name", atts)) != 0)
883 dirid = repodata_str2dir(pd->data, str, 1);
886 pd->ret = pool_error(pool, -1, "<dir .../> tag without 'name' attribute");
889 if ((str = find_attr("size", atts)) != 0)
890 filesz = strtol(str, 0, 0);
891 if ((str = find_attr("count", atts)) != 0)
892 filenum = strtol(str, 0, 0);
893 pd->dirs = solv_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
894 pd->dirs[pd->ndirs][0] = dirid;
895 pd->dirs[pd->ndirs][1] = filesz;
896 pd->dirs[pd->ndirs][2] = filenum;
913 endElement(void *userData, const char *name)
915 struct parsedata *pd = userData;
916 Pool *pool = pd->pool;
917 Solvable *s = pd->solvable;
918 Repo *repo = pd->repo;
919 Id handle = pd->handle;
923 if (pd->depth != pd->statedepth)
926 /* printf("back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth); */
930 /* ignore patterns & metadata */
931 if (pd->state == STATE_START && !strcmp(name, "patterns"))
933 if (pd->state == STATE_START && !strcmp(name, "products"))
936 if (pd->state == STATE_START && !strcmp(name, "metadata"))
939 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
948 pd->state = pd->sbtab[pd->state];
956 if (pd->kind && !s->name) /* add namespace in case of NULL name */
957 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", 0), 1);
959 s->arch = ARCH_NOARCH;
961 s->evr = ID_EMPTY; /* some patterns have this */
962 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
963 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
964 s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, pd->freshens);
965 s->conflicts = repo_fix_conflicts(repo, s->conflicts);
968 pd->solvable = s = 0;
972 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", pd->content), 1);
974 s->name = pool_str2id(pool, pd->content, 1);
977 s->arch = pool_str2id(pool, pd->content, 1);
980 s->vendor = pool_str2id(pool, pd->content, 1);
982 case STATE_RPM_GROUP:
983 repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, pd->content);
985 case STATE_RPM_LICENSE:
986 repodata_set_poolstr(pd->data, handle, SOLVABLE_LICENSE, pd->content);
994 if (strlen(pd->content) != 2 * solv_chksum_len(pd->chksumtype))
996 pd->ret = pool_error(pool, -1, "line %d: invalid checksum length for %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), solv_chksum_type2str(pd->chksumtype));
999 repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, pd->chksumtype, pd->content);
1000 /* we save the checksum to solvable id relationship for extended
1002 index = stringpool_str2id(&pd->cspool, pd->content, 1 /* create it */);
1003 if (index >= pd->ncscache)
1005 pd->cscache = solv_zextend(pd->cscache, pd->ncscache, index + 1 - pd->ncscache, sizeof(Id), 255);
1006 pd->ncscache = index + 1;
1008 /* add the checksum to the cache */
1009 pd->cscache[index] = s - pool->solvables;
1014 id = pool_str2id(pool, pd->content, 1);
1015 s->provides = repo_addid_dep(repo, s->provides, id, SOLVABLE_FILEMARKER);
1017 if ((p = strrchr(pd->content, '/')) != 0)
1020 if (pd->lastdir && !strcmp(pd->lastdirstr, pd->content))
1027 id = repodata_str2dir(pd->data, pd->content, 1);
1028 l = strlen(pd->content) + 1;
1029 if (l > pd->lastdirstrl)
1031 pd->lastdirstrl = l + 128;
1032 pd->lastdirstr = solv_realloc(pd->lastdirstr, pd->lastdirstrl);
1034 strcpy(pd->lastdirstr, pd->content);
1044 id = repodata_str2dir(pd->data, "/", 1);
1045 repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
1048 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_SUMMARY, pd->tmplang), pd->content);
1050 case STATE_DESCRIPTION:
1051 set_description_author(pd->data, handle, pd->content, pd);
1053 case STATE_CATEGORY:
1054 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_CATEGORY, pd->tmplang), pd->content);
1056 case STATE_DISTRIBUTION:
1057 repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, pd->content);
1061 repodata_set_str(pd->data, handle, SOLVABLE_URL, pd->content);
1063 case STATE_PACKAGER:
1065 repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, pd->content);
1067 case STATE_SOURCERPM:
1068 set_sourcerpm(pd->data, s, handle, pd->content);
1070 case STATE_RELNOTESURL:
1073 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1074 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, pool_str2id(pool, "releasenotes", 1));
1077 case STATE_UPDATEURL:
1080 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1081 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, pool_str2id(pool, "update", 1));
1084 case STATE_OPTIONALURL:
1087 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1088 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, pool_str2id(pool, "optional", 1));
1093 repodata_set_poolstr(pd->data, handle, PRODUCT_FLAGS, pd->content);
1097 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->tmplang), pd->content);
1101 repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_KEYWORDS, pd->content);
1103 case STATE_DISKUSAGE:
1105 commit_diskusage(pd, pd->handle);
1109 repodata_set_str(pd->data, pd->handle, SOLVABLE_ORDER, pd->content);
1113 pd->state = pd->sbtab[pd->state];
1115 /* fprintf(stderr, "back from known %d %d %d\n", pd->state, pd->depth, pd->statedepth); */
1126 characterData(void *userData, const XML_Char *s, int len)
1128 struct parsedata *pd = userData;
1134 l = pd->lcontent + len + 1;
1135 if (l > pd->acontent)
1137 pd->content = solv_realloc(pd->content, l + 256);
1138 pd->acontent = l + 256;
1140 c = pd->content + pd->lcontent;
1141 pd->lcontent += len;
1148 /*-----------------------------------------------*/
1151 #define BUFF_SIZE 8192
1155 * parse rpm-md metadata (primary, others)
1160 repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
1162 Pool *pool = repo->pool;
1163 struct parsedata pd;
1164 char buf[BUFF_SIZE];
1166 struct stateswitch *sw;
1171 now = solv_timems(0);
1172 data = repo_add_repodata(repo, flags);
1174 memset(&pd, 0, sizeof(pd));
1175 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
1177 if (!pd.swtab[sw->from])
1178 pd.swtab[sw->from] = sw;
1179 pd.sbtab[sw->to] = sw->from;
1185 pd.content = solv_malloc(256);
1189 pd.language = language && *language && strcmp(language, "en") != 0 ? language : 0;
1191 /* initialize the string pool where we will store
1192 the package checksums we know about, to get an Id
1193 we can use in a cache */
1194 stringpool_init_empty(&pd.cspool);
1195 if ((flags & REPO_EXTEND_SOLVABLES) != 0)
1197 /* setup join data */
1199 dataiterator_init(&di, pool, repo, 0, SOLVABLE_CHECKSUM, 0, 0);
1200 while (dataiterator_step(&di))
1205 if (!solv_chksum_len(di.key->type))
1207 str = repodata_chk2str(di.data, di.key->type, (const unsigned char *)di.kv.str);
1208 index = stringpool_str2id(&pd.cspool, str, 1);
1209 if (index >= pd.ncscache)
1211 pd.cscache = solv_zextend(pd.cscache, pd.ncscache, index + 1 - pd.ncscache, sizeof(Id), 255);
1212 pd.ncscache = index + 1;
1214 pd.cscache[index] = di.solvid;
1216 dataiterator_free(&di);
1219 parser = XML_ParserCreate(NULL);
1220 XML_SetUserData(parser, &pd);
1221 pd.parser = &parser;
1222 XML_SetElementHandler(parser, startElement, endElement);
1223 XML_SetCharacterDataHandler(parser, characterData);
1226 l = fread(buf, 1, sizeof(buf), fp);
1227 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
1229 pd.ret = pool_error(pool, -1, "repo_rpmmd: %s at line %u:%u", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
1235 XML_ParserFree(parser);
1236 solv_free(pd.content);
1237 solv_free(pd.lastdirstr);
1238 join_freemem(&pd.jd);
1239 stringpool_free(&pd.cspool);
1240 solv_free(pd.cscache);
1241 repodata_free_dircache(data);
1243 if (!(flags & REPO_NO_INTERNALIZE))
1244 repodata_internalize(data);
1245 POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", solv_timems(now));
1246 POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1247 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)));