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 */
86 /* rpm-md dependencies inside the
102 STATE_OBSOLETESENTRY,
103 STATE_CONFLICTSENTRY,
104 STATE_RECOMMENDSENTRY,
105 STATE_SUPPLEMENTSENTRY,
125 static struct stateswitch stateswitches[] = {
126 /** fake tag used to enclose 2 different xml files in one **/
127 { STATE_START, "rpmmd", STATE_START, 0 },
129 /** tags for different package data, we just ignore the tag **/
130 { STATE_START, "metadata", STATE_START, 0 },
131 { STATE_START, "otherdata", STATE_START, 0 },
132 { STATE_START, "filelists", STATE_START, 0 },
133 { STATE_START, "diskusagedata", STATE_START, 0 },
134 { STATE_START, "susedata", STATE_START, 0 },
136 { STATE_START, "product", STATE_SOLVABLE, 0 },
137 { STATE_START, "pattern", STATE_SOLVABLE, 0 },
138 { STATE_START, "patch", STATE_SOLVABLE, 0 },
139 { STATE_START, "package", STATE_SOLVABLE, 0 },
141 { STATE_SOLVABLE, "name", STATE_NAME, 1 },
142 { STATE_SOLVABLE, "arch", STATE_ARCH, 1 },
143 { STATE_SOLVABLE, "version", STATE_VERSION, 0 },
145 /* package attributes rpm-md */
146 { STATE_SOLVABLE, "location", STATE_LOCATION, 0 },
147 { STATE_SOLVABLE, "checksum", STATE_CHECKSUM, 1 },
149 /* resobject attributes */
151 { STATE_SOLVABLE, "summary", STATE_SUMMARY, 1 },
152 { STATE_SOLVABLE, "description", STATE_DESCRIPTION, 1 },
153 { STATE_SOLVABLE, "distribution", STATE_DISTRIBUTION, 1 },
154 { STATE_SOLVABLE, "url", STATE_URL, 1 },
155 { STATE_SOLVABLE, "packager", STATE_PACKAGER, 1 },
156 { STATE_SOLVABLE, "vendor", STATE_VENDOR, 1 },
157 { STATE_SOLVABLE, "size", STATE_SIZE, 0 },
158 { STATE_SOLVABLE, "archive-size", STATE_DOWNLOADSIZE, 1 },
159 { STATE_SOLVABLE, "install-time", STATE_INSTALLTIME, 1 },
160 { STATE_SOLVABLE, "install-only", STATE_INSTALLONLY, 1 },
161 { STATE_SOLVABLE, "time", STATE_TIME, 0 },
163 /* extended Novell/SUSE attributes (susedata.xml) */
164 { STATE_SOLVABLE, "eula", STATE_EULA, 1 },
165 { STATE_SOLVABLE, "keyword", STATE_KEYWORD, 1 },
166 { STATE_SOLVABLE, "diskusage", STATE_DISKUSAGE, 0 },
168 /* pattern attribute */
169 { STATE_SOLVABLE, "script", STATE_SCRIPT, 1 },
170 { STATE_SOLVABLE, "icon", STATE_ICON, 1 },
171 { STATE_SOLVABLE, "uservisible", STATE_USERVISIBLE, 1 },
172 { STATE_SOLVABLE, "category", STATE_CATEGORY, 1 },
173 { STATE_SOLVABLE, "order", STATE_ORDER, 1 },
174 { STATE_SOLVABLE, "includes", STATE_INCLUDES, 0 },
175 { STATE_SOLVABLE, "extends", STATE_EXTENDS, 0 },
176 { STATE_SOLVABLE, "default", STATE_DEFAULT, 1 },
177 { STATE_SOLVABLE, "install-time", STATE_INSTALL_TIME, 1 },
179 /* product attributes */
180 /* note the product type is an attribute */
181 { STATE_SOLVABLE, "release-notes-url", STATE_RELNOTESURL, 1 },
182 { STATE_SOLVABLE, "update-url", STATE_UPDATEURL, 1 },
183 { STATE_SOLVABLE, "optional-url", STATE_OPTIONALURL, 1 },
184 { STATE_SOLVABLE, "flag", STATE_FLAG, 1 },
186 { STATE_SOLVABLE, "rpm:vendor", STATE_VENDOR, 1 },
187 { STATE_SOLVABLE, "rpm:group", STATE_RPM_GROUP, 1 },
188 { STATE_SOLVABLE, "rpm:license", STATE_RPM_LICENSE, 1 },
190 /* rpm-md dependencies */
191 { STATE_SOLVABLE, "rpm:provides", STATE_PROVIDES, 0 },
192 { STATE_SOLVABLE, "rpm:requires", STATE_REQUIRES, 0 },
193 { STATE_SOLVABLE, "rpm:obsoletes", STATE_OBSOLETES, 0 },
194 { STATE_SOLVABLE, "rpm:conflicts", STATE_CONFLICTS, 0 },
195 { STATE_SOLVABLE, "rpm:recommends", STATE_RECOMMENDS , 0 },
196 { STATE_SOLVABLE, "rpm:supplements", STATE_SUPPLEMENTS, 0 },
197 { STATE_SOLVABLE, "rpm:suggests", STATE_SUGGESTS, 0 },
198 { STATE_SOLVABLE, "rpm:enhances", STATE_ENHANCES, 0 },
199 { STATE_SOLVABLE, "rpm:freshens", STATE_FRESHENS, 0 },
200 { STATE_SOLVABLE, "rpm:sourcerpm", STATE_SOURCERPM, 1 },
201 { STATE_SOLVABLE, "rpm:header-range", STATE_HEADERRANGE, 0 },
202 { STATE_SOLVABLE, "file", STATE_FILE, 1 },
203 { STATE_SOLVABLE, "changelog", STATE_CHANGELOG, 1 },
205 /* extended Novell/SUSE diskusage attributes (susedata.xml) */
206 { STATE_DISKUSAGE, "dirs", STATE_DIRS, 0 },
207 { STATE_DIRS, "dir", STATE_DIR, 0 },
209 { STATE_PROVIDES, "rpm:entry", STATE_PROVIDESENTRY, 0 },
210 { STATE_REQUIRES, "rpm:entry", STATE_REQUIRESENTRY, 0 },
211 { STATE_OBSOLETES, "rpm:entry", STATE_OBSOLETESENTRY, 0 },
212 { STATE_CONFLICTS, "rpm:entry", STATE_CONFLICTSENTRY, 0 },
213 { STATE_RECOMMENDS, "rpm:entry", STATE_RECOMMENDSENTRY, 0 },
214 { STATE_SUPPLEMENTS, "rpm:entry", STATE_SUPPLEMENTSENTRY, 0 },
215 { STATE_SUGGESTS, "rpm:entry", STATE_SUGGESTSENTRY, 0 },
216 { STATE_ENHANCES, "rpm:entry", STATE_ENHANCESENTRY, 0 },
217 { STATE_FRESHENS, "rpm:entry", STATE_FRESHENSENTRY, 0 },
219 { STATE_INCLUDES, "item", STATE_INCLUDESENTRY, 0 },
220 { STATE_EXTENDS, "item", STATE_EXTENDSENTRY, 0 },
240 struct stateswitch *swtab[NUMSTATES];
241 enum state sbtab[NUMSTATES];
243 /* temporal to store attribute tag language */
248 Id (*dirs)[3]; /* dirid, size, nfiles */
250 const char *language; /* default language */
251 Id langcache[ID_NUM_INTERNAL]; /* cache for the default language */
259 /** Hash to maps checksums to solv */
261 /** Cache of known checksums to solvable id */
263 /* the current longest index in the table */
268 langtag(struct parsedata *pd, Id tag, const char *language)
272 if (!language[0] || !strcmp(language, "en"))
274 return pool_id2langid(pd->pool, tag, language, 1);
278 if (tag >= ID_NUM_INTERNAL)
279 return pool_id2langid(pd->pool, tag, pd->language, 1);
280 if (!pd->langcache[tag])
281 pd->langcache[tag] = pool_id2langid(pd->pool, tag, pd->language, 1);
282 return pd->langcache[tag];
286 id3_cmp (const void *v1, const void *v2, void *dp)
290 return i1[0] - i2[0];
294 commit_diskusage (struct parsedata *pd, Id handle)
297 Dirpool *dp = &pd->data->dirpool;
298 /* Now sort in dirid order. This ensures that parents come before
301 solv_sort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp, 0);
302 /* Substract leaf numbers from all parents to make the numbers
303 non-cumulative. This must be done post-order (i.e. all leafs
304 adjusted before parents). We ensure this by starting at the end of
305 the array moving to the start, hence seeing leafs before parents. */
306 for (i = pd->ndirs; i--;)
308 Id p = dirpool_parent(dp, pd->dirs[i][0]);
310 for (; p; p = dirpool_parent(dp, p))
313 if (pd->dirs[j][0] == p)
317 if (pd->dirs[j][1] < pd->dirs[i][1])
320 pd->dirs[j][1] -= pd->dirs[i][1];
321 if (pd->dirs[j][2] < pd->dirs[i][2])
324 pd->dirs[j][2] -= pd->dirs[i][2];
327 /* Haven't found this parent in the list, look further if
328 we maybe find the parents parent. */
335 unsigned slen = sizeof (sbuf);
336 for (i = 0; i < pd->ndirs; i++)
338 dir2str (attr, pd->dirs[i][0], &buf, &slen);
339 fprintf (stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf);
344 for (i = 0; i < pd->ndirs; i++)
345 if (pd->dirs[i][1] || pd->dirs[i][2])
347 repodata_add_dirnumnum(pd->data, handle, SOLVABLE_DISKUSAGE, pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2]);
355 * parse 'epoch', 'ver' and 'rel', return evr Id
360 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
362 const char *e, *v, *r, *v2;
367 for (; *atts; atts += 2)
369 if (!strcmp(*atts, "epoch"))
371 else if (!strcmp(*atts, "ver"))
373 else if (!strcmp(*atts, "rel"))
376 if (e && (!*e || !strcmp(e, "0")))
380 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
382 if (v2 > v && *v2 == ':')
392 if (l > pd->acontent)
394 pd->content = solv_realloc(pd->content, l + 256);
395 pd->acontent = l + 256;
419 fprintf(stderr, "evr: %s\n", pd->content);
421 return pool_str2id(pool, pd->content, 1);
427 * find value for xml attribute
428 * I: txt, name of attribute
429 * I: atts, list of key/value attributes
430 * O: pointer to value of matching key, or NULL
434 static inline const char *
435 find_attr(const char *txt, const char **atts)
437 for (; *atts; atts += 2)
439 if (!strcmp(*atts, txt))
447 * dependency relations
450 static char *flagtab[] = {
462 * parse attributes to reldep Id
467 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts, int isreq)
470 const char *n, *f, *k;
474 marker = isreq ? -SOLVABLE_PREREQMARKER : 0;
475 for (a = atts; *a; a += 2)
477 if (!strcmp(*a, "name"))
479 else if (!strcmp(*a, "flags"))
481 else if (!strcmp(*a, "kind"))
483 else if (isreq && !strcmp(*a, "pre") && a[1][0] == '1')
484 marker = SOLVABLE_PREREQMARKER;
488 if (k && !strcmp(k, "package"))
492 int l = strlen(k) + 1 + strlen(n) + 1;
493 if (l > pd->acontent)
495 pd->content = solv_realloc(pd->content, l + 256);
496 pd->acontent = l + 256;
498 sprintf(pd->content, "%s:%s", k, n);
499 name = pool_str2id(pool, pd->content, 1);
502 name = pool_str2id(pool, (char *)n, 1);
505 Id evr = makeevr_atts(pool, pd, atts);
507 for (flags = 0; flags < 6; flags++)
508 if (!strcmp(f, flagtab[flags]))
510 flags = flags < 6 ? flags + 1 : 0;
511 id = pool_rel2id(pool, name, evr, flags, 1);
516 fprintf(stderr, "new dep %s\n", pool_dep2str(pool, id));
518 return repo_addid_dep(pd->repo, olddeps, id, marker);
523 * set_description_author
527 set_description_author(Repodata *data, Id handle, char *str, struct parsedata *pd)
533 for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
534 if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
538 /* oh my, found SUSE special author section */
541 while (l > 0 && str[l - 1] == '\n')
544 repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
546 aut = str; /* copy over */
547 while (*p == ' ' || *p == '\n')
560 while (aut != str && aut[-1] == '\n')
564 repodata_set_str(data, handle, SOLVABLE_AUTHORS, str);
567 repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
571 /*-----------------------------------------------*/
581 startElement(void *userData, const char *name, const char **atts)
583 struct parsedata *pd = userData;
584 Pool *pool = pd->pool;
585 Solvable *s = pd->solvable;
586 struct stateswitch *sw;
588 Id handle = pd->handle;
591 /* fprintf(stderr, "into %s, from %d, depth %d, statedepth %d\n", name, pd->state, pd->depth, pd->statedepth); */
593 if (pd->depth != pd->statedepth)
599 if (pd->state == STATE_START && !strcmp(name, "patterns"))
601 if (pd->state == STATE_START && !strcmp(name, "products"))
604 if (pd->state == STATE_START && !strcmp(name, "metadata"))
607 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
611 if (!pd->swtab[pd->state])
613 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++)
614 if (!strcmp(sw->ename, name))
616 if (sw->from != pd->state)
619 fprintf(stderr, "into unknown: %s\n", name);
624 pd->docontent = sw->docontent;
625 pd->statedepth = pd->depth;
629 if (!s && pd->state != STATE_SOLVABLE)
636 if (name[2] == 't' && name[3] == 't')
637 pd->kind = "pattern";
638 else if (name[1] == 'r')
639 pd->kind = "product";
640 else if (name[2] == 't' && name[3] == 'c')
643 /* to support extension metadata files like others.xml which
644 have the following structure:
646 <otherdata xmlns="http://linux.duke.edu/metadata/other"
648 <package pkgid="b78f8664cd90efe42e09a345e272997ef1b53c18"
649 name="zaptel-kmp-default"
650 arch="i586"><version epoch="0"
651 ver="1.2.10_2.6.22_rc4_git6_2" rel="70"/>
654 we need to check if the pkgid is there and if it matches
655 an already seen package, that means we don't need to create
656 a new solvable but just append the attributes to the existing
659 if ((pkgid = find_attr("pkgid", atts)) != NULL)
661 /* look at the checksum cache */
662 Id index = stringpool_str2id(&pd->cspool, pkgid, 0);
663 if (!index || index >= pd->ncscache || !pd->cscache[index])
665 pool_debug(pool, SOLV_WARN, "the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
670 pd->solvable = pool_id2solvable(pool, pd->cscache[index]);
674 /* this is a new package */
675 pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
678 pd->handle = handle = pd->solvable - pool->solvables;
679 if (pd->kind && pd->kind[1] == 'r')
681 /* products can have a type */
682 const char *type = find_attr("type", atts);
684 repodata_set_str(pd->data, handle, PRODUCT_TYPE, type);
687 fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
692 s->evr = makeevr_atts(pool, pd, atts);
697 case STATE_PROVIDESENTRY:
698 s->provides = adddep(pool, pd, s->provides, atts, 0);
703 case STATE_REQUIRESENTRY:
704 s->requires = adddep(pool, pd, s->requires, atts, 1);
706 case STATE_OBSOLETES:
709 case STATE_OBSOLETESENTRY:
710 s->obsoletes = adddep(pool, pd, s->obsoletes, atts, 0);
712 case STATE_CONFLICTS:
715 case STATE_CONFLICTSENTRY:
716 s->conflicts = adddep(pool, pd, s->conflicts, atts, 0);
718 case STATE_RECOMMENDS:
721 case STATE_RECOMMENDSENTRY:
722 s->recommends = adddep(pool, pd, s->recommends, atts, 0);
724 case STATE_SUPPLEMENTS:
727 case STATE_SUPPLEMENTSENTRY:
728 s->supplements = adddep(pool, pd, s->supplements, atts, 0);
733 case STATE_SUGGESTSENTRY:
734 s->suggests = adddep(pool, pd, s->suggests, atts, 0);
739 case STATE_ENHANCESENTRY:
740 s->enhances = adddep(pool, pd, s->enhances, atts, 0);
745 case STATE_FRESHENSENTRY:
746 pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
751 case STATE_DESCRIPTION:
752 pd->tmplang = join_dup(&pd->jd, find_attr("lang", atts));
754 case STATE_USERVISIBLE:
755 repodata_set_void(pd->data, handle, SOLVABLE_ISVISIBLE);
757 case STATE_INCLUDESENTRY:
758 str = find_attr("pattern", atts);
760 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_INCLUDES, join2(&pd->jd, "pattern", ":", str));
762 case STATE_EXTENDSENTRY:
763 str = find_attr("pattern", atts);
765 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_EXTENDS, join2(&pd->jd, "pattern", ":", str));
768 str = find_attr("href", atts);
771 repodata_set_location(pd->data, handle, 0, 0, str);
772 str = find_attr("xml:base", atts);
774 repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIABASE, str);
778 str = find_attr("type", atts);
779 pd->chksumtype = str && *str ? solv_chksum_str2type(str) : 0;
781 pd->ret = pool_error(pool, -1, "line %d: unknown checksum type: %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), str ? str : "NULL");
786 str = find_attr("build", atts);
787 if (str && (t = atoi(str)) != 0)
788 repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, t);
792 if ((str = find_attr("installed", atts)) != 0)
793 repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, strtoull(str, 0, 10));
794 if ((str = find_attr("package", atts)) != 0)
795 repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, strtoull(str, 0, 10));
797 case STATE_HEADERRANGE:
800 str = find_attr("end", atts);
801 if (str && (end = atoi(str)) != 0)
802 repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
808 <dir name="/" size="56" count="11"/>
809 <dir name="usr/" size="56" count="11"/>
810 <dir name="usr/bin/" size="38" count="10"/>
811 <dir name="usr/share/" size="18" count="1"/>
812 <dir name="usr/share/doc/" size="18" count="1"/>
816 case STATE_DISKUSAGE:
818 /* Really, do nothing, wait for <dir> tag */
823 long filesz = 0, filenum = 0;
825 if ((str = find_attr("name", atts)) != 0)
826 dirid = repodata_str2dir(pd->data, str, 1);
829 pd->ret = pool_error(pool, -1, "<dir .../> tag without 'name' attribute");
832 if ((str = find_attr("size", atts)) != 0)
833 filesz = strtol(str, 0, 0);
834 if ((str = find_attr("count", atts)) != 0)
835 filenum = strtol(str, 0, 0);
836 pd->dirs = solv_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
837 pd->dirs[pd->ndirs][0] = dirid;
838 pd->dirs[pd->ndirs][1] = filesz;
839 pd->dirs[pd->ndirs][2] = filenum;
843 case STATE_CHANGELOG:
844 pd->changelog_handle = repodata_new_handle(pd->data);
845 if ((str = find_attr("date", atts)) != 0)
846 repodata_set_num(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TIME, strtoull(str, 0, 10));
847 if ((str = find_attr("author", atts)) != 0)
848 repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_AUTHOR, str);
863 endElement(void *userData, const char *name)
865 struct parsedata *pd = userData;
866 Pool *pool = pd->pool;
867 Solvable *s = pd->solvable;
868 Repo *repo = pd->repo;
869 Id handle = pd->handle;
873 if (pd->depth != pd->statedepth)
876 /* printf("back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth); */
880 /* ignore patterns & metadata */
881 if (pd->state == STATE_START && !strcmp(name, "patterns"))
883 if (pd->state == STATE_START && !strcmp(name, "products"))
886 if (pd->state == STATE_START && !strcmp(name, "metadata"))
889 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
898 pd->state = pd->sbtab[pd->state];
906 if (pd->kind && !s->name) /* add namespace in case of NULL name */
907 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", 0), 1);
909 s->arch = ARCH_NOARCH;
911 s->evr = ID_EMPTY; /* some patterns have this */
912 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
913 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
914 s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, pd->freshens);
915 s->conflicts = repo_fix_conflicts(repo, s->conflicts);
918 pd->solvable = s = 0;
922 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", pd->content), 1);
924 s->name = pool_str2id(pool, pd->content, 1);
927 s->arch = pool_str2id(pool, pd->content, 1);
930 s->vendor = pool_str2id(pool, pd->content, 1);
932 case STATE_RPM_GROUP:
933 repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, pd->content);
935 case STATE_RPM_LICENSE:
936 repodata_set_poolstr(pd->data, handle, SOLVABLE_LICENSE, pd->content);
944 if (strlen(pd->content) != 2 * solv_chksum_len(pd->chksumtype))
946 pd->ret = pool_error(pool, -1, "line %d: invalid checksum length for %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), solv_chksum_type2str(pd->chksumtype));
949 repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, pd->chksumtype, pd->content);
950 /* we save the checksum to solvable id relationship for extended
952 index = stringpool_str2id(&pd->cspool, pd->content, 1 /* create it */);
953 if (index >= pd->ncscache)
955 pd->cscache = solv_zextend(pd->cscache, pd->ncscache, index + 1 - pd->ncscache, sizeof(Id), 255);
956 pd->ncscache = index + 1;
958 /* add the checksum to the cache */
959 pd->cscache[index] = s - pool->solvables;
964 id = pool_str2id(pool, pd->content, 1);
965 s->provides = repo_addid_dep(repo, s->provides, id, SOLVABLE_FILEMARKER);
967 if ((p = strrchr(pd->content, '/')) != 0)
970 if (pd->lastdir && !strcmp(pd->lastdirstr, pd->content))
977 id = repodata_str2dir(pd->data, pd->content, 1);
978 l = strlen(pd->content) + 1;
979 if (l > pd->lastdirstrl)
981 pd->lastdirstrl = l + 128;
982 pd->lastdirstr = solv_realloc(pd->lastdirstr, pd->lastdirstrl);
984 strcpy(pd->lastdirstr, pd->content);
994 id = repodata_str2dir(pd->data, "/", 1);
995 repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
998 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_SUMMARY, pd->tmplang), pd->content);
1000 case STATE_DESCRIPTION:
1001 set_description_author(pd->data, handle, pd->content, pd);
1003 case STATE_CATEGORY:
1004 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_CATEGORY, pd->tmplang), pd->content);
1006 case STATE_DISTRIBUTION:
1007 repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, pd->content);
1011 repodata_set_str(pd->data, handle, SOLVABLE_URL, pd->content);
1013 case STATE_PACKAGER:
1015 repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, pd->content);
1017 case STATE_SOURCERPM:
1019 repodata_set_sourcepkg(pd->data, handle, pd->content);
1021 case STATE_RELNOTESURL:
1024 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
1025 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "releasenotes", 1));
1028 case STATE_UPDATEURL:
1031 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
1032 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "update", 1));
1035 case STATE_OPTIONALURL:
1038 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
1039 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "optional", 1));
1044 repodata_add_poolstr_array(pd->data, handle, PRODUCT_FLAGS, pd->content);
1048 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->tmplang), pd->content);
1052 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_KEYWORDS, pd->content);
1054 case STATE_DISKUSAGE:
1056 commit_diskusage(pd, handle);
1060 repodata_set_str(pd->data, handle, SOLVABLE_ORDER, pd->content);
1062 case STATE_CHANGELOG:
1063 repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TEXT, pd->content);
1064 repodata_add_flexarray(pd->data, handle, SOLVABLE_CHANGELOG, pd->changelog_handle);
1065 pd->changelog_handle = 0;
1070 pd->state = pd->sbtab[pd->state];
1072 /* fprintf(stderr, "back from known %d %d %d\n", pd->state, pd->depth, pd->statedepth); */
1083 characterData(void *userData, const XML_Char *s, int len)
1085 struct parsedata *pd = userData;
1091 l = pd->lcontent + len + 1;
1092 if (l > pd->acontent)
1094 pd->content = solv_realloc(pd->content, l + 256);
1095 pd->acontent = l + 256;
1097 c = pd->content + pd->lcontent;
1098 pd->lcontent += len;
1105 /*-----------------------------------------------*/
1108 #define BUFF_SIZE 8192
1112 * parse rpm-md metadata (primary, others)
1117 repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
1119 Pool *pool = repo->pool;
1120 struct parsedata pd;
1121 char buf[BUFF_SIZE];
1123 struct stateswitch *sw;
1128 now = solv_timems(0);
1129 data = repo_add_repodata(repo, flags);
1131 memset(&pd, 0, sizeof(pd));
1132 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
1134 if (!pd.swtab[sw->from])
1135 pd.swtab[sw->from] = sw;
1136 pd.sbtab[sw->to] = sw->from;
1142 pd.content = solv_malloc(256);
1146 pd.language = language && *language && strcmp(language, "en") != 0 ? language : 0;
1148 /* initialize the string pool where we will store
1149 the package checksums we know about, to get an Id
1150 we can use in a cache */
1151 stringpool_init_empty(&pd.cspool);
1152 if ((flags & REPO_EXTEND_SOLVABLES) != 0)
1154 /* setup join data */
1156 dataiterator_init(&di, pool, repo, 0, SOLVABLE_CHECKSUM, 0, 0);
1157 while (dataiterator_step(&di))
1162 if (!solv_chksum_len(di.key->type))
1164 str = repodata_chk2str(di.data, di.key->type, (const unsigned char *)di.kv.str);
1165 index = stringpool_str2id(&pd.cspool, str, 1);
1166 if (index >= pd.ncscache)
1168 pd.cscache = solv_zextend(pd.cscache, pd.ncscache, index + 1 - pd.ncscache, sizeof(Id), 255);
1169 pd.ncscache = index + 1;
1171 pd.cscache[index] = di.solvid;
1173 dataiterator_free(&di);
1176 parser = XML_ParserCreate(NULL);
1177 XML_SetUserData(parser, &pd);
1178 pd.parser = &parser;
1179 XML_SetElementHandler(parser, startElement, endElement);
1180 XML_SetCharacterDataHandler(parser, characterData);
1183 l = fread(buf, 1, sizeof(buf), fp);
1184 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
1186 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));
1192 XML_ParserFree(parser);
1193 solv_free(pd.content);
1194 solv_free(pd.lastdirstr);
1195 join_freemem(&pd.jd);
1196 stringpool_free(&pd.cspool);
1197 solv_free(pd.cscache);
1198 repodata_free_dircache(data);
1200 if (!(flags & REPO_NO_INTERNALIZE))
1201 repodata_internalize(data);
1202 POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", solv_timems(now));
1203 POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1204 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)));