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 if (!pd->swtab[pd->state])
648 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++)
649 if (!strcmp(sw->ename, name))
651 if (sw->from != pd->state)
654 fprintf(stderr, "into unknown: %s\n", name);
659 pd->docontent = sw->docontent;
660 pd->statedepth = pd->depth;
667 if (name[2] == 't' && name[3] == 't')
668 pd->kind = "pattern";
669 else if (name[1] == 'r')
670 pd->kind = "product";
671 else if (name[2] == 't' && name[3] == 'c')
674 /* to support extension metadata files like others.xml which
675 have the following structure:
677 <otherdata xmlns="http://linux.duke.edu/metadata/other"
679 <package pkgid="b78f8664cd90efe42e09a345e272997ef1b53c18"
680 name="zaptel-kmp-default"
681 arch="i586"><version epoch="0"
682 ver="1.2.10_2.6.22_rc4_git6_2" rel="70"/>
685 we need to check if the pkgid is there and if it matches
686 an already seen package, that means we don't need to create
687 a new solvable but just append the attributes to the existing
691 if ((pkgid = find_attr("pkgid", atts)) != NULL)
693 // look at the checksum cache
694 Id index = stringpool_str2id(&pd->cspool, pkgid, 0);
695 if (!index || index >= pd->ncscache || !pd->cscache[index])
697 fprintf(stderr, "error, the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
700 pd->solvable = pool_id2solvable(pool, pd->cscache[index]);
704 /* this is a new package */
705 pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->common.repo));
707 repodata_extend(pd->data, pd->solvable - pool->solvables);
709 pd->handle = repodata_get_handle(pd->data, (pd->solvable - pool->solvables) - pd->data->start);
711 fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
716 s->evr = makeevr_atts(pool, pd, atts);
721 case STATE_PROVIDESENTRY:
722 s->provides = adddep(pool, pd, s->provides, atts, 0);
727 case STATE_REQUIRESENTRY:
728 s->requires = adddep(pool, pd, s->requires, atts, 1);
730 case STATE_OBSOLETES:
733 case STATE_OBSOLETESENTRY:
734 s->obsoletes = adddep(pool, pd, s->obsoletes, atts, 0);
736 case STATE_CONFLICTS:
739 case STATE_CONFLICTSENTRY:
740 s->conflicts = adddep(pool, pd, s->conflicts, atts, 0);
742 case STATE_RECOMMENDS:
745 case STATE_RECOMMENDSENTRY:
746 s->recommends = adddep(pool, pd, s->recommends, atts, 0);
748 case STATE_SUPPLEMENTS:
751 case STATE_SUPPLEMENTSENTRY:
752 s->supplements = adddep(pool, pd, s->supplements, atts, 0);
757 case STATE_SUGGESTSENTRY:
758 s->suggests = adddep(pool, pd, s->suggests, atts, 0);
763 case STATE_ENHANCESENTRY:
764 s->enhances = adddep(pool, pd, s->enhances, atts, 0);
769 case STATE_FRESHENSENTRY:
770 pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
773 case STATE_DESCRIPTION:
774 pd->tmplang = find_attr("lang", atts);
777 str = find_attr("href", atts);
780 const char *str2 = strrchr(str, '/');
783 char *str3 = strdup(str);
784 str3[str2 - str] = 0;
785 repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIADIR, str3);
787 repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, str2 + 1);
790 repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, str);
794 pd->tmpattr = find_attr("type", atts);
799 str = find_attr("build", atts);
800 if (str && (t = atoi(str)) != 0)
801 repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, t);
807 str = find_attr("installed", atts);
808 if (str && (k = atoi(str)) != 0)
809 repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, (k + 1023) / 1024);
810 /* XXX the "package" attribute gives the size of the rpm file,
811 i.e. the download size. Except on packman, there it seems to be
812 something else entirely, it has a value near to the other two
813 values, as if the rpm is uncompressed. */
814 str = find_attr("package", atts);
815 if (str && (k = atoi(str)) != 0)
816 repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, (k + 1023) / 1024);
819 case STATE_HEADERRANGE:
822 str = find_attr("end", atts);
823 if (str && (end = atoi(str)) != 0)
824 repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
829 <dir name="/" size="56" count="11"/>
830 <dir name="usr/" size="56" count="11"/>
831 <dir name="usr/bin/" size="38" count="10"/>
832 <dir name="usr/share/" size="18" count="1"/>
833 <dir name="usr/share/doc/" size="18" count="1"/>
837 case STATE_DISKUSAGE:
839 /* Really, do nothing, wat for <dir> tag */
844 long filesz = 0, filenum = 0;
846 if ( (str = find_attr("name", atts)) )
848 dirid = repodata_str2dir(pd->data, str, 1);
852 fprintf( stderr, "<dir .../> tag without 'name' attribute, atts = %p, *atts = %p\n", atts, *atts);
855 if ( (str = find_attr("size", atts)) )
857 filesz = strtol (str, 0, 0);
859 if ( (str = find_attr("count", atts)) )
861 filenum = strtol (str, 0, 0);
863 pd->dirs = sat_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
864 pd->dirs[pd->ndirs][0] = dirid;
865 pd->dirs[pd->ndirs][1] = filesz;
866 pd->dirs[pd->ndirs][2] = filenum;
883 endElement(void *userData, const char *name)
885 //fprintf(stderr,"-tag: %s\n", name);
886 struct parsedata *pd = userData;
887 Pool *pool = pd->common.pool;
888 Solvable *s = pd->solvable;
889 Repo *repo = pd->common.repo;
890 Id handle = pd->handle;
894 if (pd->depth != pd->statedepth)
897 // printf("back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
901 /* ignore patterns & metadata */
902 if (pd->state == STATE_START && !strcmp(name, "patterns"))
904 //if (pd->state == STATE_START && !strcmp(name, "metadata"))
906 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
915 s->arch = ARCH_NOARCH;
917 s->evr = ID_EMPTY; /* some patterns have this */
918 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
919 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
920 s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, pd->freshens);
921 s->conflicts = repo_fix_conflicts(repo, s->conflicts);
927 s->name = str2id(pool, join2( pd->kind, ":", pd->content), 1);
929 s->name = str2id(pool, pd->content, 1);
932 s->arch = str2id(pool, pd->content, 1);
935 s->vendor = str2id(pool, pd->content, 1);
937 case STATE_RPM_GROUP:
938 repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, pd->content);
940 case STATE_RPM_LICENSE:
941 repodata_set_poolstr(pd->data, handle, SOLVABLE_LICENSE, pd->content);
947 if (!strcasecmp (pd->tmpattr, "sha") || !strcasecmp (pd->tmpattr, "sha1"))
948 l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
949 else if (!strcasecmp (pd->tmpattr, "md5"))
950 l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
953 fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
956 if (strlen(pd->content) != l)
958 fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
961 repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, type, pd->content);
962 /* we save the checksum to solvable id relationship for extended
964 index = stringpool_str2id(&pd->cspool, pd->content, 1 /* create it */);
965 if (index >= pd->ncscache)
967 pd->cscache = sat_zextend(pd->cscache, pd->ncscache, index + 1 - pd->ncscache, sizeof(Id), 255);
968 pd->ncscache = index + 1;
970 /* add the checksum to the cache */
971 pd->cscache[index] = s - pool->solvables;
976 id = str2id(pool, pd->content, 1);
977 s->provides = repo_addid_dep(repo, s->provides, id, SOLVABLE_FILEMARKER);
979 if ((p = strrchr(pd->content, '/')) != 0)
982 id = repodata_str2dir(pd->data, pd->content, 1);
990 id = repodata_str2dir(pd->data, "/", 1);
991 repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
995 repodata_set_str(pd->data, handle, SOLVABLE_SUMMARY, pd->content);
997 case STATE_DESCRIPTION:
999 set_desciption_author(pd->data, handle, pd->content);
1001 case STATE_DISTRIBUTION:
1002 repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, pd->content);
1006 repodata_set_str(pd->data, handle, SOLVABLE_URL, pd->content);
1008 case STATE_PACKAGER:
1010 repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, pd->content);
1012 case STATE_SOURCERPM:
1013 set_sourcerpm(pd->data, s, handle, pd->content);
1015 case STATE_RELNOTESURL:
1018 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1019 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "releasenotes", 1));
1022 case STATE_UPDATEURL:
1025 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1026 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "update", 1));
1029 case STATE_OPTIONALURL:
1032 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1033 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "optional", 1));
1038 repodata_set_poolstr(pd->data, handle, PRODUCT_FLAGS, pd->content);
1042 repodata_set_str(pd->data, handle, PRODUCT_FLAVOR, pd->content);
1044 case STATE_REFERENCES:
1046 repodata_set_str(pd->data, handle, PRODUCT_REFERENCES, pd->content);
1050 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->language), pd->content);
1052 case STATE_DISKUSAGE:
1054 commit_diskusage (pd, pd->handle);
1059 pd->state = pd->sbtab[pd->state];
1061 // fprintf(stderr, "back from known %d %d %d\n", pd->state, pd->depth, pd->statedepth);
1072 characterData(void *userData, const XML_Char *s, int len)
1074 struct parsedata *pd = userData;
1080 l = pd->lcontent + len + 1;
1081 if (l > pd->acontent)
1083 pd->content = sat_realloc(pd->content, l + 256);
1084 pd->acontent = l + 256;
1086 c = pd->content + pd->lcontent;
1087 pd->lcontent += len;
1094 /*-----------------------------------------------*/
1097 #define BUFF_SIZE 8192
1101 * parse rpm-md metadata (primary, others)
1106 repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
1108 Pool *pool = repo->pool;
1109 struct parsedata pd;
1110 char buf[BUFF_SIZE];
1112 struct stateswitch *sw;
1114 memset(&pd, 0, sizeof(pd));
1115 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
1117 if (!pd.swtab[sw->from])
1118 pd.swtab[sw->from] = sw;
1119 pd.sbtab[sw->to] = sw->from;
1121 pd.common.pool = pool;
1122 pd.common.repo = repo;
1124 pd.data = repo_add_repodata(repo, 0);
1126 pd.content = sat_malloc(256);
1132 pd.language = language;
1134 /* initialize the string pool where we will store
1135 the package checksums we know about, to get an Id
1136 we can use in a cache */
1137 stringpool_init_empty(&pd.cspool);
1139 XML_Parser parser = XML_ParserCreate(NULL);
1140 XML_SetUserData(parser, &pd);
1141 pd.parser = &parser;
1142 XML_SetElementHandler(parser, startElement, endElement);
1143 XML_SetCharacterDataHandler(parser, characterData);
1146 l = fread(buf, 1, sizeof(buf), fp);
1147 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
1149 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));
1155 XML_ParserFree(parser);
1158 repodata_internalize(pd.data);
1159 sat_free(pd.content);
1161 stringpool_free(&pd.cspool);
1162 sat_free(pd.cscache);