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"
38 /* resobject attributes */
53 /* Novell/SUSE extended attributes */
66 STATE_CATEGORY, /* pattern and patches */
75 STATE_DISTNAME, // obsolete
76 STATE_DISTEDITION, // obsolete
86 /* rpm-md dependencies inside the
102 STATE_OBSOLETESENTRY,
103 STATE_CONFLICTSENTRY,
104 STATE_RECOMMENDSENTRY,
105 STATE_SUPPLEMENTSENTRY,
123 static struct stateswitch stateswitches[] = {
124 /** fake tag used to enclose 2 different xml files in one **/
125 { STATE_START, "rpmmd", STATE_START, 0 },
127 /** tags for different package data, we just ignore the tag **/
128 { STATE_START, "metadata", STATE_START, 0 },
129 { STATE_START, "otherdata", STATE_START, 0 },
130 { STATE_START, "diskusagedata", STATE_START, 0 },
131 { STATE_START, "susedata", STATE_START, 0 },
133 { STATE_START, "product", STATE_SOLVABLE, 0 },
134 { STATE_START, "pattern", STATE_SOLVABLE, 0 },
135 { STATE_START, "patch", STATE_SOLVABLE, 0 },
136 { STATE_START, "package", 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, "???", STATE_INSNOTIFY, 1 },
154 //{ STATE_SOLVABLE, "??", STATE_DELNOTIFY, 1 },
155 { STATE_SOLVABLE, "vendor", STATE_VENDOR, 1 },
156 { STATE_SOLVABLE, "size", STATE_SIZE, 0 },
157 { STATE_SOLVABLE, "archive-size", STATE_DOWNLOADSIZE, 1 },
158 { STATE_SOLVABLE, "install-time", STATE_INSTALLTIME, 1 },
159 { STATE_SOLVABLE, "install-only", STATE_INSTALLONLY, 1 },
160 { STATE_SOLVABLE, "time", STATE_TIME, 0 },
162 /* extended Novell/SUSE attributes (susedata.xml) */
163 { STATE_SOLVABLE, "eula", STATE_EULA, 1 },
164 { STATE_SOLVABLE, "diskusage", STATE_DISKUSAGE, 0 },
167 { STATE_SOLVABLE, "script", STATE_SCRIPT, 1 },
168 { STATE_SOLVABLE, "icon", STATE_ICON, 1 },
169 { STATE_SOLVABLE, "uservisible", STATE_USERVISIBLE, 1 },
170 { STATE_SOLVABLE, "category", STATE_CATEGORY, 1 },
171 { STATE_SOLVABLE, "default", STATE_DEFAULT, 1 },
172 { STATE_SOLVABLE, "install-time", STATE_INSTALL_TIME, 1 },
174 /* product attributes */
175 /* note the product type is an attribute */
176 { STATE_SOLVABLE, "release-notes-url", STATE_RELNOTESURL, 1 },
177 { STATE_SOLVABLE, "update-url", STATE_UPDATEURL, 1 },
178 { STATE_SOLVABLE, "optional-url", STATE_OPTIONALURL, 1 },
179 { STATE_SOLVABLE, "flag", STATE_FLAG, 1 },
180 { STATE_SOLVABLE, "flavor", STATE_FLAVOR, 1 },
181 { STATE_SOLVABLE, "references", STATE_REFERENCES, 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 },
201 /* extended Novell/SUSE dskusage attributes (suseinfo.xml) */
202 { STATE_DISKUSAGE, "dirs", STATE_DIRS, 0 },
203 { STATE_DIRS, "dir", STATE_DIR, 0 },
205 { STATE_PROVIDES, "rpm:entry", STATE_PROVIDESENTRY, 0 },
206 { STATE_REQUIRES, "rpm:entry", STATE_REQUIRESENTRY, 0 },
207 { STATE_OBSOLETES, "rpm:entry", STATE_OBSOLETESENTRY, 0 },
208 { STATE_CONFLICTS, "rpm:entry", STATE_CONFLICTSENTRY, 0 },
209 { STATE_RECOMMENDS, "rpm:entry", STATE_RECOMMENDSENTRY, 0 },
210 { STATE_SUPPLEMENTS, "rpm:entry", STATE_SUPPLEMENTSENTRY, 0 },
211 { STATE_SUGGESTS, "rpm:entry", STATE_SUGGESTSENTRY, 0 },
212 { STATE_ENHANCES, "rpm:entry", STATE_ENHANCESENTRY, 0 },
213 { STATE_FRESHENS, "rpm:entry", STATE_FRESHENSENTRY, 0 },
218 /* maxmum initial size of
219 the checksum cache */
220 #define MAX_CSCACHE 32768
221 #define CSREALLOC_STEP 1024
224 struct parsedata_common common;
235 struct stateswitch *swtab[NUMSTATES];
236 enum state sbtab[NUMSTATES];
237 /* temporal to store attribute tag language */
240 // used to store tmp attributes
241 // while the tag ends
246 Id (*dirs)[3]; // dirid, size, nfiles
248 Id langcache[ID_NUM_INTERNAL];
249 /** system language */
250 const char *language;
252 /** Hash to maps checksums to solv */
254 /** Cache of known checksums to solvable id */
256 /* the current longest index in the table */
261 langtag(struct parsedata *pd, Id tag, const char *language)
263 if (language && !language[0])
265 if (!language || tag >= ID_NUM_INTERNAL)
266 return pool_id2langid(pd->common.repo->pool, tag, language, 1);
267 return pool_id2langid(pd->common.repo->pool, tag, language, 1);
268 if (!pd->langcache[tag])
269 pd->langcache[tag] = pool_id2langid(pd->common.repo->pool, tag, language, 1);
270 return pd->langcache[tag];
274 id3_cmp (const void *v1, const void *v2)
278 return i1[0] - i2[0];
282 commit_diskusage (struct parsedata *pd, unsigned handle)
285 Dirpool *dp = &pd->data->dirpool;
286 /* Now sort in dirid order. This ensures that parents come before
289 qsort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp);
290 /* Substract leaf numbers from all parents to make the numbers
291 non-cumulative. This must be done post-order (i.e. all leafs
292 adjusted before parents). We ensure this by starting at the end of
293 the array moving to the start, hence seeing leafs before parents. */
294 for (i = pd->ndirs; i--;)
296 unsigned p = dirpool_parent(dp, pd->dirs[i][0]);
298 for (; p; p = dirpool_parent(dp, p))
301 if (pd->dirs[j][0] == p)
305 if (pd->dirs[j][1] < pd->dirs[i][1])
308 pd->dirs[j][1] -= pd->dirs[i][1];
309 if (pd->dirs[j][2] < pd->dirs[i][2])
312 pd->dirs[j][2] -= pd->dirs[i][2];
315 /* Haven't found this parent in the list, look further if
316 we maybe find the parents parent. */
323 unsigned slen = sizeof (sbuf);
324 for (i = 0; i < pd->ndirs; i++)
326 dir2str (attr, pd->dirs[i][0], &buf, &slen);
327 fprintf (stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf);
332 for (i = 0; i < pd->ndirs; i++)
333 if (pd->dirs[i][1] || pd->dirs[i][2])
335 repodata_add_dirnumnum(pd->data, handle, SOLVABLE_DISKUSAGE, pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2]);
343 * parse 'epoch', 'ver' and 'rel', return evr Id
348 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
350 const char *e, *v, *r, *v2;
355 for (; *atts; atts += 2)
357 if (!strcmp(*atts, "epoch"))
359 else if (!strcmp(*atts, "ver"))
361 else if (!strcmp(*atts, "rel"))
364 if (e && !strcmp(e, "0"))
368 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
370 if (v2 > v && *v2 == ':')
380 if (l > pd->acontent)
382 pd->content = sat_realloc(pd->content, l + 256);
383 pd->acontent = l + 256;
407 fprintf(stderr, "evr: %s\n", pd->content);
409 return str2id(pool, pd->content, 1);
415 * find value for xml attribute
416 * I: txt, name of attribute
417 * I: atts, list of key/value attributes
418 * O: pointer to value of matching key, or NULL
422 static inline const char *
423 find_attr(const char *txt, const char **atts)
425 for (; *atts; atts += 2)
427 if (!strcmp(*atts, txt))
435 * dependency relations
438 static char *flagtab[] = {
450 * parse attributes to reldep Id
455 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts, int isreq)
458 const char *n, *f, *k;
462 marker = isreq ? -SOLVABLE_PREREQMARKER : 0;
463 for (a = atts; *a; a += 2)
465 if (!strcmp(*a, "name"))
467 else if (!strcmp(*a, "flags"))
469 else if (!strcmp(*a, "kind"))
471 else if (isreq && !strcmp(*a, "pre") && a[1][0] == '1')
472 marker = SOLVABLE_PREREQMARKER;
476 if (k && !strcmp(k, "package"))
480 int l = strlen(k) + 1 + strlen(n) + 1;
481 if (l > pd->acontent)
483 pd->content = sat_realloc(pd->content, l + 256);
484 pd->acontent = l + 256;
486 sprintf(pd->content, "%s:%s", k, n);
487 name = str2id(pool, pd->content, 1);
490 name = str2id(pool, (char *)n, 1);
493 Id evr = makeevr_atts(pool, pd, atts);
495 for (flags = 0; flags < 6; flags++)
496 if (!strcmp(f, flagtab[flags]))
498 flags = flags < 6 ? flags + 1 : 0;
499 id = rel2id(pool, name, evr, flags, 1);
504 fprintf(stderr, "new dep %s%s%s\n", id2str(pool, d), id2rel(pool, d), id2evr(pool, d));
506 return repo_addid_dep(pd->common.repo, olddeps, id, marker);
511 * set_desciption_author
516 set_desciption_author(Repodata *data, Id handle, char *str)
522 for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
523 if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
527 /* oh my, found SUSE special author section */
530 while (l > 0 && str[l - 1] == '\n')
533 repodata_set_str(data, handle, SOLVABLE_DESCRIPTION, str);
535 aut = str; /* copy over */
536 while (*p == ' ' || *p == '\n')
549 while (aut != str && aut[-1] == '\n')
553 repodata_set_str(data, handle, SOLVABLE_AUTHORS, str);
556 repodata_set_str(data, handle, SOLVABLE_DESCRIPTION, str);
566 set_sourcerpm(Repodata *data, Solvable *s, Id handle, char *sourcerpm)
568 const char *p, *sevr, *sarch, *name, *evr;
571 p = strrchr(sourcerpm, '.');
572 if (!p || strcmp(p, ".rpm") != 0)
575 while (p > sourcerpm && *p != '.')
577 if (*p != '.' || p == sourcerpm)
580 while (p > sourcerpm && *p != '-')
582 if (*p != '-' || p == sourcerpm)
585 while (p > sourcerpm && *p != '-')
587 if (*p != '-' || p == sourcerpm)
590 pool = s->repo->pool;
591 name = id2str(pool, s->name);
592 evr = id2str(pool, s->evr);
593 if (!strcmp(sarch, "src.rpm"))
594 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_SRC);
595 else if (!strcmp(sarch, "nosrc.rpm"))
596 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_NOSRC);
598 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, strn2id(pool, sarch, strlen(sarch) - 4, 1));
599 if (!strncmp(sevr, evr, sarch - sevr - 1) && evr[sarch - sevr - 1] == 0)
600 repodata_set_void(data, handle, SOLVABLE_SOURCEEVR);
602 repodata_set_id(data, handle, SOLVABLE_SOURCEEVR, strn2id(pool, sevr, sarch - sevr - 1, 1));
603 if (!strncmp(sourcerpm, name, sevr - sourcerpm - 1) && name[sevr - sourcerpm -
605 repodata_set_void(data, handle, SOLVABLE_SOURCENAME);
607 repodata_set_id(data, handle, SOLVABLE_SOURCENAME, strn2id(pool, sourcerpm, sevr - sourcerpm - 1, 1));
610 /*-----------------------------------------------*/
620 startElement(void *userData, const char *name, const char **atts)
622 //fprintf(stderr,"+tag: %s\n", name);
623 struct parsedata *pd = userData;
624 Pool *pool = pd->common.pool;
625 Solvable *s = pd->solvable;
626 struct stateswitch *sw;
628 Id handle = pd->handle;
630 // fprintf(stderr, "into %s, from %d, depth %d, statedepth %d\n", name, pd->state, pd->depth, pd->statedepth);
632 if (pd->depth != pd->statedepth)
638 if (pd->state == STATE_START && !strcmp(name, "patterns"))
640 //if (pd->state == STATE_START && !strcmp(name, "metadata"))
642 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
646 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++)
647 if (!strcmp(sw->ename, name))
649 if (sw->from != pd->state)
652 fprintf(stderr, "into unknown: %s\n", name);
657 pd->docontent = sw->docontent;
658 pd->statedepth = pd->depth;
665 if (name[2] == 't' && name[3] == 't')
666 pd->kind = "pattern";
667 else if (name[1] == 'r')
668 pd->kind = "product";
669 else if (name[2] == 't' && name[3] == 'c')
672 /* to support extension metadata files like others.xml which
673 have the following structure:
675 <otherdata xmlns="http://linux.duke.edu/metadata/other"
677 <package pkgid="b78f8664cd90efe42e09a345e272997ef1b53c18"
678 name="zaptel-kmp-default"
679 arch="i586"><version epoch="0"
680 ver="1.2.10_2.6.22_rc4_git6_2" rel="70"/>
683 we need to check if the pkgid is there and if it matches
684 an already seen package, that means we don't need to create
685 a new solvable but just append the attributes to the existing
689 if ((pkgid = find_attr("pkgid", atts)) != NULL)
691 // look at the checksum cache
692 Id index = stringpool_str2id(&pd->cspool, pkgid, 0);
693 if (!index || index >= pd->ncscache || !pd->cscache[index])
695 fprintf(stderr, "error, the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
698 pd->solvable = pool_id2solvable(pool, pd->cscache[index]);
702 /* this is a new package */
703 pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->common.repo));
705 repodata_extend(pd->data, pd->solvable - pool->solvables);
707 pd->handle = repodata_get_handle(pd->data, (pd->solvable - pool->solvables) - pd->data->start);
709 fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
714 s->evr = makeevr_atts(pool, pd, atts);
719 case STATE_PROVIDESENTRY:
720 s->provides = adddep(pool, pd, s->provides, atts, 0);
725 case STATE_REQUIRESENTRY:
726 s->requires = adddep(pool, pd, s->requires, atts, 1);
728 case STATE_OBSOLETES:
731 case STATE_OBSOLETESENTRY:
732 s->obsoletes = adddep(pool, pd, s->obsoletes, atts, 0);
734 case STATE_CONFLICTS:
737 case STATE_CONFLICTSENTRY:
738 s->conflicts = adddep(pool, pd, s->conflicts, atts, 0);
740 case STATE_RECOMMENDS:
743 case STATE_RECOMMENDSENTRY:
744 s->recommends = adddep(pool, pd, s->recommends, atts, 0);
746 case STATE_SUPPLEMENTS:
749 case STATE_SUPPLEMENTSENTRY:
750 s->supplements = adddep(pool, pd, s->supplements, atts, 0);
755 case STATE_SUGGESTSENTRY:
756 s->suggests = adddep(pool, pd, s->suggests, atts, 0);
761 case STATE_ENHANCESENTRY:
762 s->enhances = adddep(pool, pd, s->enhances, atts, 0);
767 case STATE_FRESHENSENTRY:
768 pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
771 case STATE_DESCRIPTION:
772 pd->tmplang = find_attr("lang", atts);
775 str = find_attr("href", atts);
778 const char *str2 = strrchr(str, '/');
781 char *str3 = strdup(str);
782 str3[str2 - str] = 0;
783 repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIADIR, str3);
785 repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, str2 + 1);
788 repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, str);
792 pd->tmpattr = find_attr("type", atts);
797 str = find_attr("build", atts);
798 if (str && (t = atoi(str)) != 0)
799 repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, t);
805 str = find_attr("installed", atts);
806 if (str && (k = atoi(str)) != 0)
807 repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, (k + 1023) / 1024);
808 /* XXX the "package" attribute gives the size of the rpm file,
809 i.e. the download size. Except on packman, there it seems to be
810 something else entirely, it has a value near to the other two
811 values, as if the rpm is uncompressed. */
812 str = find_attr("package", atts);
813 if (str && (k = atoi(str)) != 0)
814 repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, (k + 1023) / 1024);
817 case STATE_HEADERRANGE:
820 str = find_attr("end", atts);
821 if (str && (end = atoi(str)) != 0)
822 repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
827 <dir name="/" size="56" count="11"/>
828 <dir name="usr/" size="56" count="11"/>
829 <dir name="usr/bin/" size="38" count="10"/>
830 <dir name="usr/share/" size="18" count="1"/>
831 <dir name="usr/share/doc/" size="18" count="1"/>
835 case STATE_DISKUSAGE:
837 /* Really, do nothing, wat for <dir> tag */
842 long filesz = 0, filenum = 0;
844 if ( (str = find_attr("name", atts)) )
846 dirid = repodata_str2dir(pd->data, str, 1);
850 fprintf( stderr, "<dir .../> tag without 'name' attribute, atts = %p, *atts = %p\n", atts, *atts);
853 if ( (str = find_attr("size", atts)) )
855 filesz = strtol (str, 0, 0);
857 if ( (str = find_attr("count", atts)) )
859 filenum = strtol (str, 0, 0);
861 pd->dirs = sat_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
862 pd->dirs[pd->ndirs][0] = dirid;
863 pd->dirs[pd->ndirs][1] = filesz;
864 pd->dirs[pd->ndirs][2] = filenum;
881 endElement(void *userData, const char *name)
883 //fprintf(stderr,"-tag: %s\n", name);
884 struct parsedata *pd = userData;
885 Pool *pool = pd->common.pool;
886 Solvable *s = pd->solvable;
887 Repo *repo = pd->common.repo;
888 Id handle = pd->handle;
892 if (pd->depth != pd->statedepth)
895 // printf("back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
899 /* ignore patterns & metadata */
900 if (pd->state == STATE_START && !strcmp(name, "patterns"))
902 //if (pd->state == STATE_START && !strcmp(name, "metadata"))
904 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
913 s->arch = ARCH_NOARCH;
915 s->evr = ID_EMPTY; /* some patterns have this */
916 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
917 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
918 s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, pd->freshens);
919 s->conflicts = repo_fix_conflicts(repo, s->conflicts);
925 s->name = str2id(pool, join2( pd->kind, ":", pd->content), 1);
927 s->name = str2id(pool, pd->content, 1);
930 s->arch = str2id(pool, pd->content, 1);
933 s->vendor = str2id(pool, pd->content, 1);
935 case STATE_RPM_GROUP:
936 repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, pd->content);
938 case STATE_RPM_LICENSE:
939 repodata_set_poolstr(pd->data, handle, SOLVABLE_LICENSE, pd->content);
945 if (!strcasecmp (pd->tmpattr, "sha") || !strcasecmp (pd->tmpattr, "sha1"))
946 l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
947 else if (!strcasecmp (pd->tmpattr, "md5"))
948 l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
951 fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
954 if (strlen(pd->content) != l)
956 fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
959 repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, type, pd->content);
960 /* we save the checksum to solvable id relationship for extended
962 index = stringpool_str2id(&pd->cspool, pd->content, 1 /* create it */);
963 if (index >= pd->ncscache)
965 pd->cscache = sat_zextend(pd->cscache, pd->ncscache, index + 1 - pd->ncscache, sizeof(Id), 255);
966 pd->ncscache = index + 1;
968 /* add the checksum to the cache */
969 pd->cscache[index] = s - pool->solvables;
974 id = str2id(pool, pd->content, 1);
975 s->provides = repo_addid_dep(repo, s->provides, id, SOLVABLE_FILEMARKER);
977 if ((p = strrchr(pd->content, '/')) != 0)
980 id = repodata_str2dir(pd->data, pd->content, 1);
988 id = repodata_str2dir(pd->data, "/", 1);
989 repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
993 repodata_set_str(pd->data, handle, SOLVABLE_SUMMARY, pd->content);
995 case STATE_DESCRIPTION:
997 set_desciption_author(pd->data, handle, pd->content);
999 case STATE_DISTRIBUTION:
1000 repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, pd->content);
1004 repodata_set_str(pd->data, handle, SOLVABLE_URL, pd->content);
1006 case STATE_PACKAGER:
1008 repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, pd->content);
1010 case STATE_SOURCERPM:
1011 set_sourcerpm(pd->data, s, handle, pd->content);
1013 case STATE_RELNOTESURL:
1016 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1017 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "releasenotes", 1));
1020 case STATE_UPDATEURL:
1023 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1024 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "update", 1));
1027 case STATE_OPTIONALURL:
1030 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1031 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "optional", 1));
1036 repodata_set_poolstr(pd->data, handle, PRODUCT_FLAGS, pd->content);
1040 repodata_set_str(pd->data, handle, PRODUCT_FLAVOR, pd->content);
1042 case STATE_REFERENCES:
1044 repodata_set_str(pd->data, handle, PRODUCT_REFERENCES, pd->content);
1048 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->language), pd->content);
1050 case STATE_DISKUSAGE:
1052 commit_diskusage (pd, pd->handle);
1057 pd->state = pd->sbtab[pd->state];
1059 // fprintf(stderr, "back from known %d %d %d\n", pd->state, pd->depth, pd->statedepth);
1070 characterData(void *userData, const XML_Char *s, int len)
1072 struct parsedata *pd = userData;
1078 l = pd->lcontent + len + 1;
1079 if (l > pd->acontent)
1081 pd->content = sat_realloc(pd->content, l + 256);
1082 pd->acontent = l + 256;
1084 c = pd->content + pd->lcontent;
1085 pd->lcontent += len;
1092 /*-----------------------------------------------*/
1095 #define BUFF_SIZE 8192
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;
1108 char buf[BUFF_SIZE];
1110 struct stateswitch *sw;
1112 memset(&pd, 0, sizeof(pd));
1113 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
1115 if (!pd.swtab[sw->from])
1116 pd.swtab[sw->from] = sw;
1117 pd.sbtab[sw->to] = sw->from;
1119 pd.common.pool = pool;
1120 pd.common.repo = repo;
1122 pd.data = repo_add_repodata(repo, 0);
1124 pd.content = sat_malloc(256);
1130 pd.language = language;
1132 /* initialize the string pool where we will store
1133 the package checksums we know about, to get an Id
1134 we can use in a cache */
1135 stringpool_init_empty(&pd.cspool);
1137 XML_Parser parser = XML_ParserCreate(NULL);
1138 XML_SetUserData(parser, &pd);
1139 pd.parser = &parser;
1140 XML_SetElementHandler(parser, startElement, endElement);
1141 XML_SetCharacterDataHandler(parser, characterData);
1144 l = fread(buf, 1, sizeof(buf), fp);
1145 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
1147 fprintf(stderr, "repo_rpmmd: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
1153 XML_ParserFree(parser);
1156 repodata_internalize(pd.data);
1157 sat_free(pd.content);
1159 stringpool_free(&pd.cspool);
1160 sat_free(pd.cscache);