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"
22 #ifdef ENABLE_COMPLEX_DEPS
23 #include "pool_parserpmrichdep.h"
41 /* resobject attributes */
56 /* Novell/SUSE extended attributes */
69 /* pattern attributes */
70 STATE_CATEGORY, /* pattern and patches */
88 /* rpm-md dependencies inside the
104 STATE_OBSOLETESENTRY,
105 STATE_CONFLICTSENTRY,
106 STATE_RECOMMENDSENTRY,
107 STATE_SUPPLEMENTSENTRY,
127 static struct stateswitch stateswitches[] = {
128 /** fake tag used to enclose 2 different xml files in one **/
129 { STATE_START, "rpmmd", STATE_START, 0 },
131 /** tags for different package data, we just ignore the tag **/
132 { STATE_START, "metadata", STATE_START, 0 },
133 { STATE_START, "otherdata", STATE_START, 0 },
134 { STATE_START, "filelists", STATE_START, 0 },
135 { STATE_START, "diskusagedata", STATE_START, 0 },
136 { STATE_START, "susedata", STATE_START, 0 },
138 { STATE_START, "product", STATE_SOLVABLE, 0 },
139 { STATE_START, "pattern", STATE_SOLVABLE, 0 },
140 { STATE_START, "patch", STATE_SOLVABLE, 0 },
141 { STATE_START, "package", STATE_SOLVABLE, 0 },
143 { STATE_SOLVABLE, "name", STATE_NAME, 1 },
144 { STATE_SOLVABLE, "arch", STATE_ARCH, 1 },
145 { STATE_SOLVABLE, "version", STATE_VERSION, 0 },
147 /* package attributes rpm-md */
148 { STATE_SOLVABLE, "location", STATE_LOCATION, 0 },
149 { STATE_SOLVABLE, "checksum", STATE_CHECKSUM, 1 },
151 /* resobject attributes */
153 { STATE_SOLVABLE, "summary", STATE_SUMMARY, 1 },
154 { STATE_SOLVABLE, "description", STATE_DESCRIPTION, 1 },
155 { STATE_SOLVABLE, "distribution", STATE_DISTRIBUTION, 1 },
156 { STATE_SOLVABLE, "url", STATE_URL, 1 },
157 { STATE_SOLVABLE, "packager", STATE_PACKAGER, 1 },
158 { STATE_SOLVABLE, "vendor", STATE_VENDOR, 1 },
159 { STATE_SOLVABLE, "size", STATE_SIZE, 0 },
160 { STATE_SOLVABLE, "archive-size", STATE_DOWNLOADSIZE, 1 },
161 { STATE_SOLVABLE, "install-time", STATE_INSTALLTIME, 1 },
162 { STATE_SOLVABLE, "install-only", STATE_INSTALLONLY, 1 },
163 { STATE_SOLVABLE, "time", STATE_TIME, 0 },
165 /* extended Novell/SUSE attributes (susedata.xml) */
166 { STATE_SOLVABLE, "eula", STATE_EULA, 1 },
167 { STATE_SOLVABLE, "keyword", STATE_KEYWORD, 1 },
168 { STATE_SOLVABLE, "diskusage", STATE_DISKUSAGE, 0 },
170 /* pattern attribute */
171 { STATE_SOLVABLE, "script", STATE_SCRIPT, 1 },
172 { STATE_SOLVABLE, "icon", STATE_ICON, 1 },
173 { STATE_SOLVABLE, "uservisible", STATE_USERVISIBLE, 1 },
174 { STATE_SOLVABLE, "category", STATE_CATEGORY, 1 },
175 { STATE_SOLVABLE, "order", STATE_ORDER, 1 },
176 { STATE_SOLVABLE, "includes", STATE_INCLUDES, 0 },
177 { STATE_SOLVABLE, "extends", STATE_EXTENDS, 0 },
178 { STATE_SOLVABLE, "default", STATE_DEFAULT, 1 },
179 { STATE_SOLVABLE, "install-time", STATE_INSTALL_TIME, 1 },
181 /* product attributes */
182 /* note the product type is an attribute */
183 { STATE_SOLVABLE, "release-notes-url", STATE_RELNOTESURL, 1 },
184 { STATE_SOLVABLE, "update-url", STATE_UPDATEURL, 1 },
185 { STATE_SOLVABLE, "optional-url", STATE_OPTIONALURL, 1 },
186 { STATE_SOLVABLE, "flag", STATE_FLAG, 1 },
188 { STATE_SOLVABLE, "rpm:vendor", STATE_VENDOR, 1 },
189 { STATE_SOLVABLE, "rpm:group", STATE_RPM_GROUP, 1 },
190 { STATE_SOLVABLE, "rpm:license", STATE_RPM_LICENSE, 1 },
192 /* rpm-md dependencies */
193 { STATE_SOLVABLE, "rpm:provides", STATE_PROVIDES, 0 },
194 { STATE_SOLVABLE, "rpm:requires", STATE_REQUIRES, 0 },
195 { STATE_SOLVABLE, "rpm:obsoletes", STATE_OBSOLETES, 0 },
196 { STATE_SOLVABLE, "rpm:conflicts", STATE_CONFLICTS, 0 },
197 { STATE_SOLVABLE, "rpm:recommends", STATE_RECOMMENDS , 0 },
198 { STATE_SOLVABLE, "rpm:supplements", STATE_SUPPLEMENTS, 0 },
199 { STATE_SOLVABLE, "rpm:suggests", STATE_SUGGESTS, 0 },
200 { STATE_SOLVABLE, "rpm:enhances", STATE_ENHANCES, 0 },
201 { STATE_SOLVABLE, "rpm:freshens", STATE_FRESHENS, 0 },
202 { STATE_SOLVABLE, "rpm:sourcerpm", STATE_SOURCERPM, 1 },
203 { STATE_SOLVABLE, "rpm:header-range", STATE_HEADERRANGE, 0 },
204 { STATE_SOLVABLE, "file", STATE_FILE, 1 },
205 { STATE_SOLVABLE, "changelog", STATE_CHANGELOG, 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 },
242 struct stateswitch *swtab[NUMSTATES];
243 enum state sbtab[NUMSTATES];
245 /* temporal to store attribute tag language */
250 Id (*dirs)[3]; /* dirid, size, nfiles */
252 const char *language; /* default language */
253 Id langcache[ID_NUM_INTERNAL]; /* cache for the default language */
261 /** Hash to maps checksums to solv */
263 /** Cache of known checksums to solvable id */
265 /* the current longest index in the table */
270 langtag(struct parsedata *pd, Id tag, const char *language)
274 if (!language[0] || !strcmp(language, "en"))
276 return pool_id2langid(pd->pool, tag, language, 1);
280 if (tag >= ID_NUM_INTERNAL)
281 return pool_id2langid(pd->pool, tag, pd->language, 1);
282 if (!pd->langcache[tag])
283 pd->langcache[tag] = pool_id2langid(pd->pool, tag, pd->language, 1);
284 return pd->langcache[tag];
288 id3_cmp (const void *v1, const void *v2, void *dp)
292 return i1[0] - i2[0];
296 commit_diskusage (struct parsedata *pd, Id handle)
299 Dirpool *dp = &pd->data->dirpool;
300 /* Now sort in dirid order. This ensures that parents come before
303 solv_sort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp, 0);
304 /* Substract leaf numbers from all parents to make the numbers
305 non-cumulative. This must be done post-order (i.e. all leafs
306 adjusted before parents). We ensure this by starting at the end of
307 the array moving to the start, hence seeing leafs before parents. */
308 for (i = pd->ndirs; i--;)
310 Id p = dirpool_parent(dp, pd->dirs[i][0]);
312 for (; p; p = dirpool_parent(dp, p))
315 if (pd->dirs[j][0] == p)
319 if (pd->dirs[j][1] < pd->dirs[i][1])
322 pd->dirs[j][1] -= pd->dirs[i][1];
323 if (pd->dirs[j][2] < pd->dirs[i][2])
326 pd->dirs[j][2] -= pd->dirs[i][2];
329 /* Haven't found this parent in the list, look further if
330 we maybe find the parents parent. */
337 unsigned slen = sizeof (sbuf);
338 for (i = 0; i < pd->ndirs; i++)
340 dir2str (attr, pd->dirs[i][0], &buf, &slen);
341 fprintf (stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf);
346 for (i = 0; i < pd->ndirs; i++)
347 if (pd->dirs[i][1] || pd->dirs[i][2])
349 repodata_add_dirnumnum(pd->data, handle, SOLVABLE_DISKUSAGE, pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2]);
357 * parse 'epoch', 'ver' and 'rel', return evr Id
362 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
364 const char *e, *v, *r, *v2;
369 for (; *atts; atts += 2)
371 if (!strcmp(*atts, "epoch"))
373 else if (!strcmp(*atts, "ver"))
375 else if (!strcmp(*atts, "rel"))
378 if (e && (!*e || !strcmp(e, "0")))
382 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
384 if (v2 > v && *v2 == ':')
394 if (l > pd->acontent)
396 pd->content = solv_realloc(pd->content, l + 256);
397 pd->acontent = l + 256;
421 fprintf(stderr, "evr: %s\n", pd->content);
423 return pool_str2id(pool, pd->content, 1);
429 * find value for xml attribute
430 * I: txt, name of attribute
431 * I: atts, list of key/value attributes
432 * O: pointer to value of matching key, or NULL
436 static inline const char *
437 find_attr(const char *txt, const char **atts)
439 for (; *atts; atts += 2)
441 if (!strcmp(*atts, txt))
449 * dependency relations
452 static char *flagtab[] = {
464 * parse attributes to reldep Id
469 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts, int isreq)
472 const char *n, *f, *k;
476 marker = isreq ? -SOLVABLE_PREREQMARKER : 0;
477 for (a = atts; *a; a += 2)
479 if (!strcmp(*a, "name"))
481 else if (!strcmp(*a, "flags"))
483 else if (!strcmp(*a, "kind"))
485 else if (isreq && !strcmp(*a, "pre") && a[1][0] == '1')
486 marker = SOLVABLE_PREREQMARKER;
490 if (k && !strcmp(k, "package"))
494 int l = strlen(k) + 1 + strlen(n) + 1;
495 if (l > pd->acontent)
497 pd->content = solv_realloc(pd->content, l + 256);
498 pd->acontent = l + 256;
500 sprintf(pd->content, "%s:%s", k, n);
501 id = pool_str2id(pool, pd->content, 1);
503 #ifdef ENABLE_COMPLEX_DEPS
504 else if (!f && n[0] == '(')
506 id = pool_parserpmrichdep(pool, n);
512 id = pool_str2id(pool, (char *)n, 1);
515 Id evr = makeevr_atts(pool, pd, atts);
517 for (flags = 0; flags < 6; flags++)
518 if (!strcmp(f, flagtab[flags]))
520 flags = flags < 6 ? flags + 1 : 0;
521 id = pool_rel2id(pool, id, evr, flags, 1);
524 fprintf(stderr, "new dep %s\n", pool_dep2str(pool, id));
526 return repo_addid_dep(pd->repo, olddeps, id, marker);
531 * set_description_author
535 set_description_author(Repodata *data, Id handle, char *str, struct parsedata *pd)
541 for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
542 if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
546 /* oh my, found SUSE special author section */
549 while (l > 0 && str[l - 1] == '\n')
552 repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
554 aut = str; /* copy over */
555 while (*p == ' ' || *p == '\n')
568 while (aut != str && aut[-1] == '\n')
572 repodata_set_str(data, handle, SOLVABLE_AUTHORS, str);
575 repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
579 /*-----------------------------------------------*/
589 startElement(void *userData, const char *name, const char **atts)
591 struct parsedata *pd = userData;
592 Pool *pool = pd->pool;
593 Solvable *s = pd->solvable;
594 struct stateswitch *sw;
596 Id handle = pd->handle;
599 /* fprintf(stderr, "into %s, from %d, depth %d, statedepth %d\n", name, pd->state, pd->depth, pd->statedepth); */
601 if (pd->depth != pd->statedepth)
607 if (pd->state == STATE_START && !strcmp(name, "patterns"))
609 if (pd->state == STATE_START && !strcmp(name, "products"))
612 if (pd->state == STATE_START && !strcmp(name, "metadata"))
615 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
619 if (!pd->swtab[pd->state])
621 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++)
622 if (!strcmp(sw->ename, name))
624 if (sw->from != pd->state)
627 fprintf(stderr, "into unknown: %s\n", name);
632 pd->docontent = sw->docontent;
633 pd->statedepth = pd->depth;
637 if (!s && pd->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
667 if ((pkgid = find_attr("pkgid", atts)) != NULL)
669 /* look at the checksum cache */
670 Id index = stringpool_str2id(&pd->cspool, pkgid, 0);
671 if (!index || index >= pd->ncscache || !pd->cscache[index])
673 pool_debug(pool, SOLV_WARN, "the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
678 pd->solvable = pool_id2solvable(pool, pd->cscache[index]);
682 /* this is a new package */
683 pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
686 pd->handle = handle = pd->solvable - pool->solvables;
687 if (pd->kind && pd->kind[1] == 'r')
689 /* products can have a type */
690 const char *type = find_attr("type", atts);
692 repodata_set_str(pd->data, handle, PRODUCT_TYPE, type);
695 fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
700 s->evr = makeevr_atts(pool, pd, atts);
705 case STATE_PROVIDESENTRY:
706 s->provides = adddep(pool, pd, s->provides, atts, 0);
711 case STATE_REQUIRESENTRY:
712 s->requires = adddep(pool, pd, s->requires, atts, 1);
714 case STATE_OBSOLETES:
717 case STATE_OBSOLETESENTRY:
718 s->obsoletes = adddep(pool, pd, s->obsoletes, atts, 0);
720 case STATE_CONFLICTS:
723 case STATE_CONFLICTSENTRY:
724 s->conflicts = adddep(pool, pd, s->conflicts, atts, 0);
726 case STATE_RECOMMENDS:
729 case STATE_RECOMMENDSENTRY:
730 s->recommends = adddep(pool, pd, s->recommends, atts, 0);
732 case STATE_SUPPLEMENTS:
735 case STATE_SUPPLEMENTSENTRY:
736 s->supplements = adddep(pool, pd, s->supplements, atts, 0);
741 case STATE_SUGGESTSENTRY:
742 s->suggests = adddep(pool, pd, s->suggests, atts, 0);
747 case STATE_ENHANCESENTRY:
748 s->enhances = adddep(pool, pd, s->enhances, atts, 0);
753 case STATE_FRESHENSENTRY:
754 pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
759 case STATE_DESCRIPTION:
760 pd->tmplang = join_dup(&pd->jd, find_attr("lang", atts));
762 case STATE_USERVISIBLE:
763 repodata_set_void(pd->data, handle, SOLVABLE_ISVISIBLE);
765 case STATE_INCLUDESENTRY:
766 str = find_attr("pattern", atts);
768 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_INCLUDES, join2(&pd->jd, "pattern", ":", str));
770 case STATE_EXTENDSENTRY:
771 str = find_attr("pattern", atts);
773 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_EXTENDS, join2(&pd->jd, "pattern", ":", str));
776 str = find_attr("href", atts);
780 const char *base = find_attr("xml:base", atts);
781 if (base && !strncmp(base, "media:", 6))
783 /* check for the media number in the fragment */
784 int l = strlen(base);
785 while (l && base[l - 1] >= '0' && base[l - 1] <= '9')
787 if (l && base[l - 1] == '#' && base[l])
788 medianr = atoi(base + l);
790 repodata_set_location(pd->data, handle, medianr, 0, str);
792 repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIABASE, base);
796 str = find_attr("type", atts);
797 pd->chksumtype = str && *str ? solv_chksum_str2type(str) : 0;
799 pd->ret = pool_error(pool, -1, "line %d: unknown checksum type: %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), str ? str : "NULL");
804 str = find_attr("build", atts);
805 if (str && (t = atoi(str)) != 0)
806 repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, t);
810 if ((str = find_attr("installed", atts)) != 0)
811 repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, strtoull(str, 0, 10));
812 if ((str = find_attr("package", atts)) != 0)
813 repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, strtoull(str, 0, 10));
815 case STATE_HEADERRANGE:
818 str = find_attr("end", atts);
819 if (str && (end = atoi(str)) != 0)
820 repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
826 <dir name="/" size="56" count="11"/>
827 <dir name="usr/" size="56" count="11"/>
828 <dir name="usr/bin/" size="38" count="10"/>
829 <dir name="usr/share/" size="18" count="1"/>
830 <dir name="usr/share/doc/" size="18" count="1"/>
834 case STATE_DISKUSAGE:
836 /* Really, do nothing, wait for <dir> tag */
841 long filesz = 0, filenum = 0;
843 if ((str = find_attr("name", atts)) != 0)
844 dirid = repodata_str2dir(pd->data, str, 1);
847 pd->ret = pool_error(pool, -1, "<dir .../> tag without 'name' attribute");
851 dirid = repodata_str2dir(pd->data, "/", 1);
852 if ((str = find_attr("size", atts)) != 0)
853 filesz = strtol(str, 0, 0);
854 if ((str = find_attr("count", atts)) != 0)
855 filenum = strtol(str, 0, 0);
856 pd->dirs = solv_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
857 pd->dirs[pd->ndirs][0] = dirid;
858 pd->dirs[pd->ndirs][1] = filesz;
859 pd->dirs[pd->ndirs][2] = filenum;
863 case STATE_CHANGELOG:
864 pd->changelog_handle = repodata_new_handle(pd->data);
865 if ((str = find_attr("date", atts)) != 0)
866 repodata_set_num(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TIME, strtoull(str, 0, 10));
867 if ((str = find_attr("author", atts)) != 0)
868 repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_AUTHOR, str);
883 endElement(void *userData, const char *name)
885 struct parsedata *pd = userData;
886 Pool *pool = pd->pool;
887 Solvable *s = pd->solvable;
888 Repo *repo = pd->repo;
889 Id handle = pd->handle;
893 if (pd->depth != pd->statedepth)
896 /* printf("back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth); */
900 /* ignore patterns & metadata */
901 if (pd->state == STATE_START && !strcmp(name, "patterns"))
903 if (pd->state == STATE_START && !strcmp(name, "products"))
906 if (pd->state == STATE_START && !strcmp(name, "metadata"))
909 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
918 pd->state = pd->sbtab[pd->state];
926 if (pd->kind && !s->name) /* add namespace in case of NULL name */
927 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", 0), 1);
929 s->arch = ARCH_NOARCH;
931 s->evr = ID_EMPTY; /* some patterns have this */
932 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
933 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
934 s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, pd->freshens);
935 s->conflicts = repo_fix_conflicts(repo, s->conflicts);
938 pd->solvable = s = 0;
942 s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", pd->content), 1);
944 s->name = pool_str2id(pool, pd->content, 1);
947 s->arch = pool_str2id(pool, pd->content, 1);
950 s->vendor = pool_str2id(pool, pd->content, 1);
952 case STATE_RPM_GROUP:
953 repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, pd->content);
955 case STATE_RPM_LICENSE:
956 repodata_set_poolstr(pd->data, handle, SOLVABLE_LICENSE, pd->content);
964 if (strlen(pd->content) != 2 * solv_chksum_len(pd->chksumtype))
966 pd->ret = pool_error(pool, -1, "line %d: invalid checksum length for %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), solv_chksum_type2str(pd->chksumtype));
969 repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, pd->chksumtype, pd->content);
970 /* we save the checksum to solvable id relationship for extended
972 index = stringpool_str2id(&pd->cspool, pd->content, 1 /* create it */);
973 if (index >= pd->ncscache)
975 pd->cscache = solv_zextend(pd->cscache, pd->ncscache, index + 1 - pd->ncscache, sizeof(Id), 255);
976 pd->ncscache = index + 1;
978 /* add the checksum to the cache */
979 pd->cscache[index] = s - pool->solvables;
984 id = pool_str2id(pool, pd->content, 1);
985 s->provides = repo_addid_dep(repo, s->provides, id, SOLVABLE_FILEMARKER);
987 if ((p = strrchr(pd->content, '/')) != 0)
990 if (pd->lastdir && !strcmp(pd->lastdirstr, pd->content))
997 id = repodata_str2dir(pd->data, pd->content, 1);
998 l = strlen(pd->content) + 1;
999 if (l > pd->lastdirstrl)
1001 pd->lastdirstrl = l + 128;
1002 pd->lastdirstr = solv_realloc(pd->lastdirstr, pd->lastdirstrl);
1004 strcpy(pd->lastdirstr, pd->content);
1014 id = repodata_str2dir(pd->data, "/", 1);
1015 repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
1018 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_SUMMARY, pd->tmplang), pd->content);
1020 case STATE_DESCRIPTION:
1021 set_description_author(pd->data, handle, pd->content, pd);
1023 case STATE_CATEGORY:
1024 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_CATEGORY, pd->tmplang), pd->content);
1026 case STATE_DISTRIBUTION:
1027 repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, pd->content);
1031 repodata_set_str(pd->data, handle, SOLVABLE_URL, pd->content);
1033 case STATE_PACKAGER:
1035 repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, pd->content);
1037 case STATE_SOURCERPM:
1039 repodata_set_sourcepkg(pd->data, handle, pd->content);
1041 case STATE_RELNOTESURL:
1044 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
1045 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "releasenotes", 1));
1048 case STATE_UPDATEURL:
1051 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
1052 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "update", 1));
1055 case STATE_OPTIONALURL:
1058 repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
1059 repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "optional", 1));
1064 repodata_add_poolstr_array(pd->data, handle, PRODUCT_FLAGS, pd->content);
1068 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->tmplang), pd->content);
1072 repodata_add_poolstr_array(pd->data, handle, SOLVABLE_KEYWORDS, pd->content);
1074 case STATE_DISKUSAGE:
1076 commit_diskusage(pd, handle);
1080 repodata_set_str(pd->data, handle, SOLVABLE_ORDER, pd->content);
1082 case STATE_CHANGELOG:
1083 repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TEXT, pd->content);
1084 repodata_add_flexarray(pd->data, handle, SOLVABLE_CHANGELOG, pd->changelog_handle);
1085 pd->changelog_handle = 0;
1090 pd->state = pd->sbtab[pd->state];
1092 /* fprintf(stderr, "back from known %d %d %d\n", pd->state, pd->depth, pd->statedepth); */
1103 characterData(void *userData, const XML_Char *s, int len)
1105 struct parsedata *pd = userData;
1111 l = pd->lcontent + len + 1;
1112 if (l > pd->acontent)
1114 pd->content = solv_realloc(pd->content, l + 256);
1115 pd->acontent = l + 256;
1117 c = pd->content + pd->lcontent;
1118 pd->lcontent += len;
1125 /*-----------------------------------------------*/
1128 #define BUFF_SIZE 8192
1132 * parse rpm-md metadata (primary, others)
1137 repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
1139 Pool *pool = repo->pool;
1140 struct parsedata pd;
1141 char buf[BUFF_SIZE];
1143 struct stateswitch *sw;
1148 now = solv_timems(0);
1149 data = repo_add_repodata(repo, flags);
1151 memset(&pd, 0, sizeof(pd));
1152 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
1154 if (!pd.swtab[sw->from])
1155 pd.swtab[sw->from] = sw;
1156 pd.sbtab[sw->to] = sw->from;
1162 pd.content = solv_malloc(256);
1166 pd.language = language && *language && strcmp(language, "en") != 0 ? language : 0;
1168 /* initialize the string pool where we will store
1169 the package checksums we know about, to get an Id
1170 we can use in a cache */
1171 stringpool_init_empty(&pd.cspool);
1172 if ((flags & REPO_EXTEND_SOLVABLES) != 0)
1174 /* setup join data */
1176 dataiterator_init(&di, pool, repo, 0, SOLVABLE_CHECKSUM, 0, 0);
1177 while (dataiterator_step(&di))
1182 if (!solv_chksum_len(di.key->type))
1184 str = repodata_chk2str(di.data, di.key->type, (const unsigned char *)di.kv.str);
1185 index = stringpool_str2id(&pd.cspool, str, 1);
1186 if (index >= pd.ncscache)
1188 pd.cscache = solv_zextend(pd.cscache, pd.ncscache, index + 1 - pd.ncscache, sizeof(Id), 255);
1189 pd.ncscache = index + 1;
1191 pd.cscache[index] = di.solvid;
1193 dataiterator_free(&di);
1196 parser = XML_ParserCreate(NULL);
1197 XML_SetUserData(parser, &pd);
1198 pd.parser = &parser;
1199 XML_SetElementHandler(parser, startElement, endElement);
1200 XML_SetCharacterDataHandler(parser, characterData);
1203 l = fread(buf, 1, sizeof(buf), fp);
1204 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
1206 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));
1212 XML_ParserFree(parser);
1213 solv_free(pd.content);
1214 solv_free(pd.lastdirstr);
1215 join_freemem(&pd.jd);
1216 stringpool_free(&pd.cspool);
1217 solv_free(pd.cscache);
1218 repodata_free_dircache(data);
1220 if (!(flags & REPO_NO_INTERNALIZE))
1221 repodata_internalize(data);
1222 POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", solv_timems(now));
1223 POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1224 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)));