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 */
67 STATE_CATEGORY, /* pattern and patches */
76 STATE_DISTNAME, // obsolete
77 STATE_DISTEDITION, // obsolete
85 /* rpm-md dependencies inside the
101 STATE_OBSOLETESENTRY,
102 STATE_CONFLICTSENTRY,
103 STATE_RECOMMENDSENTRY,
104 STATE_SUPPLEMENTSENTRY,
122 static struct stateswitch stateswitches[] = {
123 /** fake tag used to enclose 2 different xml files in one **/
124 { STATE_START, "rpmmd", STATE_START, 0 },
126 /** tags for different package data, we just ignore the tag **/
127 { STATE_START, "metadata", STATE_START, 0 },
128 { STATE_START, "otherdata", STATE_START, 0 },
129 { STATE_START, "diskusagedata", STATE_START, 0 },
130 { STATE_START, "susedata", STATE_START, 0 },
132 { STATE_START, "product", STATE_SOLVABLE, 0 },
133 { STATE_START, "pattern", STATE_SOLVABLE, 0 },
134 { STATE_START, "patch", STATE_SOLVABLE, 0 },
135 { STATE_START, "package", STATE_SOLVABLE, 0 },
137 { STATE_SOLVABLE, "name", STATE_NAME, 1 },
138 { STATE_SOLVABLE, "arch", STATE_ARCH, 1 },
139 { STATE_SOLVABLE, "version", STATE_VERSION, 0 },
141 // package attributes rpm-md
142 { STATE_SOLVABLE, "location", STATE_LOCATION, 0 },
143 { STATE_SOLVABLE, "checksum", STATE_CHECKSUM, 1 },
145 /* resobject attributes */
147 { STATE_SOLVABLE, "summary", STATE_SUMMARY, 1 },
148 { STATE_SOLVABLE, "description", STATE_DESCRIPTION, 1 },
149 { STATE_SOLVABLE, "distribution", STATE_DISTRIBUTION, 1 },
150 { STATE_SOLVABLE, "url", STATE_URL, 1 },
151 { STATE_SOLVABLE, "packager", STATE_PACKAGER, 1 },
152 //{ STATE_SOLVABLE, "???", STATE_INSNOTIFY, 1 },
153 //{ STATE_SOLVABLE, "??", STATE_DELNOTIFY, 1 },
154 { STATE_SOLVABLE, "vendor", STATE_VENDOR, 1 },
155 { STATE_SOLVABLE, "size", STATE_SIZE, 0 },
156 { STATE_SOLVABLE, "archive-size", STATE_DOWNLOADSIZE, 1 },
157 { STATE_SOLVABLE, "install-time", STATE_INSTALLTIME, 1 },
158 { STATE_SOLVABLE, "install-only", STATE_INSTALLONLY, 1 },
159 { STATE_SOLVABLE, "time", STATE_TIME, 0 },
161 /* extended Novell/SUSE attributes (susedata.xml) */
162 { STATE_SOLVABLE, "eula", STATE_EULA, 1 },
163 { STATE_SOLVABLE, "keyword", STATE_KEYWORD, 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 },
181 { STATE_SOLVABLE, "rpm:vendor", STATE_VENDOR, 1 },
182 { STATE_SOLVABLE, "rpm:group", STATE_RPM_GROUP, 1 },
183 { STATE_SOLVABLE, "rpm:license", STATE_RPM_LICENSE, 1 },
185 /* rpm-md dependencies */
186 { STATE_SOLVABLE, "rpm:provides", STATE_PROVIDES, 0 },
187 { STATE_SOLVABLE, "rpm:requires", STATE_REQUIRES, 0 },
188 { STATE_SOLVABLE, "rpm:obsoletes", STATE_OBSOLETES, 0 },
189 { STATE_SOLVABLE, "rpm:conflicts", STATE_CONFLICTS, 0 },
190 { STATE_SOLVABLE, "rpm:recommends", STATE_RECOMMENDS , 0 },
191 { STATE_SOLVABLE, "rpm:supplements", STATE_SUPPLEMENTS, 0 },
192 { STATE_SOLVABLE, "rpm:suggests", STATE_SUGGESTS, 0 },
193 { STATE_SOLVABLE, "rpm:enhances", STATE_ENHANCES, 0 },
194 { STATE_SOLVABLE, "rpm:freshens", STATE_FRESHENS, 0 },
195 { STATE_SOLVABLE, "rpm:sourcerpm", STATE_SOURCERPM, 1 },
196 { STATE_SOLVABLE, "rpm:header-range", STATE_HEADERRANGE, 0 },
197 { STATE_SOLVABLE, "file", STATE_FILE, 1 },
199 /* extended Novell/SUSE diskusage attributes (susedata.xml) */
200 { STATE_DISKUSAGE, "dirs", STATE_DIRS, 0 },
201 { STATE_DIRS, "dir", STATE_DIR, 0 },
203 { STATE_PROVIDES, "rpm:entry", STATE_PROVIDESENTRY, 0 },
204 { STATE_REQUIRES, "rpm:entry", STATE_REQUIRESENTRY, 0 },
205 { STATE_OBSOLETES, "rpm:entry", STATE_OBSOLETESENTRY, 0 },
206 { STATE_CONFLICTS, "rpm:entry", STATE_CONFLICTSENTRY, 0 },
207 { STATE_RECOMMENDS, "rpm:entry", STATE_RECOMMENDSENTRY, 0 },
208 { STATE_SUPPLEMENTS, "rpm:entry", STATE_SUPPLEMENTSENTRY, 0 },
209 { STATE_SUGGESTS, "rpm:entry", STATE_SUGGESTSENTRY, 0 },
210 { STATE_ENHANCES, "rpm:entry", STATE_ENHANCESENTRY, 0 },
211 { STATE_FRESHENS, "rpm:entry", STATE_FRESHENSENTRY, 0 },
216 /* maxmum initial size of
217 the checksum cache */
218 #define MAX_CSCACHE 32768
219 #define CSREALLOC_STEP 1024
222 struct parsedata_common common;
233 struct stateswitch *swtab[NUMSTATES];
234 enum state sbtab[NUMSTATES];
235 /* temporal to store attribute tag language */
238 // used to store tmp attributes
239 // while the tag ends
244 Id (*dirs)[3]; // dirid, size, nfiles
246 Id langcache[ID_NUM_INTERNAL];
247 /** system language */
248 const char *language;
250 /** Hash to maps checksums to solv */
252 /** Cache of known checksums to solvable id */
254 /* the current longest index in the table */
259 langtag(struct parsedata *pd, Id tag, const char *language)
261 if (language && !language[0])
263 if (!language || tag >= ID_NUM_INTERNAL)
264 return pool_id2langid(pd->common.repo->pool, tag, language, 1);
265 return pool_id2langid(pd->common.repo->pool, tag, language, 1);
266 if (!pd->langcache[tag])
267 pd->langcache[tag] = pool_id2langid(pd->common.repo->pool, tag, language, 1);
268 return pd->langcache[tag];
272 id3_cmp (const void *v1, const void *v2, void *dp)
276 return i1[0] - i2[0];
280 commit_diskusage (struct parsedata *pd, unsigned handle)
283 Dirpool *dp = &pd->data->dirpool;
284 /* Now sort in dirid order. This ensures that parents come before
287 sat_sort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp, 0);
288 /* Substract leaf numbers from all parents to make the numbers
289 non-cumulative. This must be done post-order (i.e. all leafs
290 adjusted before parents). We ensure this by starting at the end of
291 the array moving to the start, hence seeing leafs before parents. */
292 for (i = pd->ndirs; i--;)
294 unsigned p = dirpool_parent(dp, pd->dirs[i][0]);
296 for (; p; p = dirpool_parent(dp, p))
299 if (pd->dirs[j][0] == p)
303 if (pd->dirs[j][1] < pd->dirs[i][1])
306 pd->dirs[j][1] -= pd->dirs[i][1];
307 if (pd->dirs[j][2] < pd->dirs[i][2])
310 pd->dirs[j][2] -= pd->dirs[i][2];
313 /* Haven't found this parent in the list, look further if
314 we maybe find the parents parent. */
321 unsigned slen = sizeof (sbuf);
322 for (i = 0; i < pd->ndirs; i++)
324 dir2str (attr, pd->dirs[i][0], &buf, &slen);
325 fprintf (stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf);
330 for (i = 0; i < pd->ndirs; i++)
331 if (pd->dirs[i][1] || pd->dirs[i][2])
333 repodata_add_dirnumnum(pd->data, handle, SOLVABLE_DISKUSAGE, pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2]);
341 * parse 'epoch', 'ver' and 'rel', return evr Id
346 makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
348 const char *e, *v, *r, *v2;
353 for (; *atts; atts += 2)
355 if (!strcmp(*atts, "epoch"))
357 else if (!strcmp(*atts, "ver"))
359 else if (!strcmp(*atts, "rel"))
362 if (e && !strcmp(e, "0"))
366 for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
368 if (v2 > v && *v2 == ':')
378 if (l > pd->acontent)
380 pd->content = sat_realloc(pd->content, l + 256);
381 pd->acontent = l + 256;
405 fprintf(stderr, "evr: %s\n", pd->content);
407 return str2id(pool, pd->content, 1);
413 * find value for xml attribute
414 * I: txt, name of attribute
415 * I: atts, list of key/value attributes
416 * O: pointer to value of matching key, or NULL
420 static inline const char *
421 find_attr(const char *txt, const char **atts)
423 for (; *atts; atts += 2)
425 if (!strcmp(*atts, txt))
433 * dependency relations
436 static char *flagtab[] = {
448 * parse attributes to reldep Id
453 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts, int isreq)
456 const char *n, *f, *k;
460 marker = isreq ? -SOLVABLE_PREREQMARKER : 0;
461 for (a = atts; *a; a += 2)
463 if (!strcmp(*a, "name"))
465 else if (!strcmp(*a, "flags"))
467 else if (!strcmp(*a, "kind"))
469 else if (isreq && !strcmp(*a, "pre") && a[1][0] == '1')
470 marker = SOLVABLE_PREREQMARKER;
474 if (k && !strcmp(k, "package"))
478 int l = strlen(k) + 1 + strlen(n) + 1;
479 if (l > pd->acontent)
481 pd->content = sat_realloc(pd->content, l + 256);
482 pd->acontent = l + 256;
484 sprintf(pd->content, "%s:%s", k, n);
485 name = str2id(pool, pd->content, 1);
488 name = str2id(pool, (char *)n, 1);
491 Id evr = makeevr_atts(pool, pd, atts);
493 for (flags = 0; flags < 6; flags++)
494 if (!strcmp(f, flagtab[flags]))
496 flags = flags < 6 ? flags + 1 : 0;
497 id = rel2id(pool, name, evr, flags, 1);
502 fprintf(stderr, "new dep %s%s%s\n", id2str(pool, d), id2rel(pool, d), id2evr(pool, d));
504 return repo_addid_dep(pd->common.repo, olddeps, id, marker);
509 * set_desciption_author
514 set_desciption_author(Repodata *data, Id handle, char *str)
520 for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
521 if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
525 /* oh my, found SUSE special author section */
528 while (l > 0 && str[l - 1] == '\n')
531 repodata_set_str(data, handle, SOLVABLE_DESCRIPTION, str);
533 aut = str; /* copy over */
534 while (*p == ' ' || *p == '\n')
547 while (aut != str && aut[-1] == '\n')
551 repodata_set_str(data, handle, SOLVABLE_AUTHORS, str);
554 repodata_set_str(data, handle, SOLVABLE_DESCRIPTION, str);
564 set_sourcerpm(Repodata *data, Solvable *s, Id handle, char *sourcerpm)
566 const char *p, *sevr, *sarch, *name, *evr;
569 p = strrchr(sourcerpm, '.');
570 if (!p || strcmp(p, ".rpm") != 0)
573 while (p > sourcerpm && *p != '.')
575 if (*p != '.' || p == sourcerpm)
578 while (p > sourcerpm && *p != '-')
580 if (*p != '-' || p == sourcerpm)
583 while (p > sourcerpm && *p != '-')
585 if (*p != '-' || p == sourcerpm)
588 pool = s->repo->pool;
589 if (!strcmp(sarch, "src.rpm"))
590 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_SRC);
591 else if (!strcmp(sarch, "nosrc.rpm"))
592 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_NOSRC);
594 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, strn2id(pool, sarch, strlen(sarch) - 4, 1));
595 evr = id2str(pool, s->evr);
596 if (evr && !strncmp(sevr, evr, sarch - sevr - 1) && evr[sarch - sevr - 1] == 0)
597 repodata_set_void(data, handle, SOLVABLE_SOURCEEVR);
599 repodata_set_id(data, handle, SOLVABLE_SOURCEEVR, strn2id(pool, sevr, sarch - sevr - 1, 1));
600 name = id2str(pool, s->name);
601 if (name && !strncmp(sourcerpm, name, sevr - sourcerpm - 1) && name[sevr - sourcerpm - 1] == 0)
602 repodata_set_void(data, handle, SOLVABLE_SOURCENAME);
604 repodata_set_id(data, handle, SOLVABLE_SOURCENAME, strn2id(pool, sourcerpm, sevr - sourcerpm - 1, 1));
607 /*-----------------------------------------------*/
617 startElement(void *userData, const char *name, const char **atts)
619 //fprintf(stderr,"+tag: %s\n", name);
620 struct parsedata *pd = userData;
621 Pool *pool = pd->common.pool;
622 Solvable *s = pd->solvable;
623 struct stateswitch *sw;
625 Id handle = pd->handle;
627 // fprintf(stderr, "into %s, from %d, depth %d, statedepth %d\n", name, pd->state, pd->depth, pd->statedepth);
629 if (pd->depth != pd->statedepth)
635 if (pd->state == STATE_START && !strcmp(name, "patterns"))
637 //if (pd->state == STATE_START && !strcmp(name, "metadata"))
639 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
643 if (!pd->swtab[pd->state])
645 for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++)
646 if (!strcmp(sw->ename, name))
648 if (sw->from != pd->state)
651 fprintf(stderr, "into unknown: %s\n", name);
656 pd->docontent = sw->docontent;
657 pd->statedepth = pd->depth;
664 if (name[2] == 't' && name[3] == 't')
665 pd->kind = "pattern";
666 else if (name[1] == 'r')
667 pd->kind = "product";
668 else if (name[2] == 't' && name[3] == 'c')
671 /* to support extension metadata files like others.xml which
672 have the following structure:
674 <otherdata xmlns="http://linux.duke.edu/metadata/other"
676 <package pkgid="b78f8664cd90efe42e09a345e272997ef1b53c18"
677 name="zaptel-kmp-default"
678 arch="i586"><version epoch="0"
679 ver="1.2.10_2.6.22_rc4_git6_2" rel="70"/>
682 we need to check if the pkgid is there and if it matches
683 an already seen package, that means we don't need to create
684 a new solvable but just append the attributes to the existing
688 if ((pkgid = find_attr("pkgid", atts)) != NULL)
690 // look at the checksum cache
691 Id index = stringpool_str2id(&pd->cspool, pkgid, 0);
692 if (!index || index >= pd->ncscache || !pd->cscache[index])
694 fprintf(stderr, "error, the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
697 pd->solvable = pool_id2solvable(pool, pd->cscache[index]);
701 /* this is a new package */
702 pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->common.repo));
705 pd->handle = pd->solvable - pool->solvables;
707 fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
712 s->evr = makeevr_atts(pool, pd, atts);
717 case STATE_PROVIDESENTRY:
718 s->provides = adddep(pool, pd, s->provides, atts, 0);
723 case STATE_REQUIRESENTRY:
724 s->requires = adddep(pool, pd, s->requires, atts, 1);
726 case STATE_OBSOLETES:
729 case STATE_OBSOLETESENTRY:
730 s->obsoletes = adddep(pool, pd, s->obsoletes, atts, 0);
732 case STATE_CONFLICTS:
735 case STATE_CONFLICTSENTRY:
736 s->conflicts = adddep(pool, pd, s->conflicts, atts, 0);
738 case STATE_RECOMMENDS:
741 case STATE_RECOMMENDSENTRY:
742 s->recommends = adddep(pool, pd, s->recommends, atts, 0);
744 case STATE_SUPPLEMENTS:
747 case STATE_SUPPLEMENTSENTRY:
748 s->supplements = adddep(pool, pd, s->supplements, atts, 0);
753 case STATE_SUGGESTSENTRY:
754 s->suggests = adddep(pool, pd, s->suggests, atts, 0);
759 case STATE_ENHANCESENTRY:
760 s->enhances = adddep(pool, pd, s->enhances, atts, 0);
765 case STATE_FRESHENSENTRY:
766 pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
769 case STATE_DESCRIPTION:
770 pd->tmplang = find_attr("lang", atts);
773 str = find_attr("href", atts);
775 repodata_set_location(pd->data, handle, 0, 0, str);
778 pd->tmpattr = find_attr("type", atts);
783 str = find_attr("build", atts);
784 if (str && (t = atoi(str)) != 0)
785 repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, t);
791 str = find_attr("installed", atts);
792 if (str && (k = atoi(str)) != 0)
793 repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, (k + 1023) / 1024);
794 /* XXX the "package" attribute gives the size of the rpm file,
795 i.e. the download size. Except on packman, there it seems to be
796 something else entirely, it has a value near to the other two
797 values, as if the rpm is uncompressed. */
798 str = find_attr("package", atts);
799 if (str && (k = atoi(str)) != 0)
800 repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, (k + 1023) / 1024);
803 case STATE_HEADERRANGE:
806 str = find_attr("end", atts);
807 if (str && (end = atoi(str)) != 0)
808 repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
813 <dir name="/" size="56" count="11"/>
814 <dir name="usr/" size="56" count="11"/>
815 <dir name="usr/bin/" size="38" count="10"/>
816 <dir name="usr/share/" size="18" count="1"/>
817 <dir name="usr/share/doc/" size="18" count="1"/>
821 case STATE_DISKUSAGE:
823 /* Really, do nothing, wat for <dir> tag */
828 long filesz = 0, filenum = 0;
830 if ( (str = find_attr("name", atts)) )
832 dirid = repodata_str2dir(pd->data, str, 1);
836 fprintf( stderr, "<dir .../> tag without 'name' attribute, atts = %p, *atts = %p\n",
837 (void *)atts, *atts);
840 if ( (str = find_attr("size", atts)) )
842 filesz = strtol (str, 0, 0);
844 if ( (str = find_attr("count", atts)) )
846 filenum = strtol (str, 0, 0);
848 pd->dirs = sat_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
849 pd->dirs[pd->ndirs][0] = dirid;
850 pd->dirs[pd->ndirs][1] = filesz;
851 pd->dirs[pd->ndirs][2] = filenum;
868 endElement(void *userData, const char *name)
870 //fprintf(stderr,"-tag: %s\n", name);
871 struct parsedata *pd = userData;
872 Pool *pool = pd->common.pool;
873 Solvable *s = pd->solvable;
874 Repo *repo = pd->common.repo;
875 Id handle = pd->handle;
879 if (pd->depth != pd->statedepth)
882 // printf("back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
886 /* ignore patterns & metadata */
887 if (pd->state == STATE_START && !strcmp(name, "patterns"))
889 //if (pd->state == STATE_START && !strcmp(name, "metadata"))
891 if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
899 if ( pd->kind && !s->name ) /* add namespace in case of NULL name */
900 s->name = str2id(pool, join2( pd->kind, ":", ""), 1);
902 s->arch = ARCH_NOARCH;
904 s->evr = ID_EMPTY; /* some patterns have this */
905 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
906 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
907 s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, pd->freshens);
908 s->conflicts = repo_fix_conflicts(repo, s->conflicts);
914 s->name = str2id(pool, join2( pd->kind, ":", pd->content), 1);
916 s->name = str2id(pool, pd->content, 1);
919 s->arch = str2id(pool, pd->content, 1);
922 s->vendor = str2id(pool, pd->content, 1);
924 case STATE_RPM_GROUP:
925 repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, pd->content);
927 case STATE_RPM_LICENSE:
928 repodata_set_poolstr(pd->data, handle, SOLVABLE_LICENSE, pd->content);
934 if (!strcasecmp (pd->tmpattr, "sha") || !strcasecmp (pd->tmpattr, "sha1"))
935 l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
936 else if (!strcasecmp (pd->tmpattr, "sha256"))
937 l = SIZEOF_SHA256 * 2, type = REPOKEY_TYPE_SHA256;
938 else if (!strcasecmp (pd->tmpattr, "md5"))
939 l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
942 fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
945 if (strlen(pd->content) != l)
947 fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
950 repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, type, pd->content);
951 /* we save the checksum to solvable id relationship for extended
953 index = stringpool_str2id(&pd->cspool, pd->content, 1 /* create it */);
954 if (index >= pd->ncscache)
956 pd->cscache = sat_zextend(pd->cscache, pd->ncscache, index + 1 - pd->ncscache, sizeof(Id), 255);
957 pd->ncscache = index + 1;
959 /* add the checksum to the cache */
960 pd->cscache[index] = s - pool->solvables;
965 id = str2id(pool, pd->content, 1);
966 s->provides = repo_addid_dep(repo, s->provides, id, SOLVABLE_FILEMARKER);
968 if ((p = strrchr(pd->content, '/')) != 0)
971 id = repodata_str2dir(pd->data, pd->content, 1);
979 id = repodata_str2dir(pd->data, "/", 1);
980 repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
984 repodata_set_str(pd->data, handle, SOLVABLE_SUMMARY, pd->content);
986 case STATE_DESCRIPTION:
988 set_desciption_author(pd->data, handle, pd->content);
990 case STATE_DISTRIBUTION:
991 repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, pd->content);
995 repodata_set_str(pd->data, handle, SOLVABLE_URL, pd->content);
999 repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, pd->content);
1001 case STATE_SOURCERPM:
1002 set_sourcerpm(pd->data, s, handle, pd->content);
1004 case STATE_RELNOTESURL:
1007 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1008 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "releasenotes", 1));
1011 case STATE_UPDATEURL:
1014 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1015 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "update", 1));
1018 case STATE_OPTIONALURL:
1021 repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
1022 repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "optional", 1));
1027 repodata_set_poolstr(pd->data, handle, PRODUCT_FLAGS, pd->content);
1031 repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->language), pd->content);
1035 repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_KEYWORDS, pd->content);
1037 case STATE_DISKUSAGE:
1039 commit_diskusage (pd, pd->handle);
1044 pd->state = pd->sbtab[pd->state];
1046 // fprintf(stderr, "back from known %d %d %d\n", pd->state, pd->depth, pd->statedepth);
1057 characterData(void *userData, const XML_Char *s, int len)
1059 struct parsedata *pd = userData;
1065 l = pd->lcontent + len + 1;
1066 if (l > pd->acontent)
1068 pd->content = sat_realloc(pd->content, l + 256);
1069 pd->acontent = l + 256;
1071 c = pd->content + pd->lcontent;
1072 pd->lcontent += len;
1079 /*-----------------------------------------------*/
1082 #define BUFF_SIZE 8192
1086 * parse rpm-md metadata (primary, others)
1091 repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
1093 Pool *pool = repo->pool;
1094 struct parsedata pd;
1095 char buf[BUFF_SIZE];
1097 struct stateswitch *sw;
1101 now = sat_timems(0);
1102 if (!(flags & REPO_REUSE_REPODATA))
1103 data = repo_add_repodata(repo, 0);
1105 data = repo_last_repodata(repo);
1107 memset(&pd, 0, sizeof(pd));
1108 for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
1110 if (!pd.swtab[sw->from])
1111 pd.swtab[sw->from] = sw;
1112 pd.sbtab[sw->to] = sw->from;
1114 pd.common.pool = pool;
1115 pd.common.repo = repo;
1119 pd.content = sat_malloc(256);
1125 pd.language = language;
1127 /* initialize the string pool where we will store
1128 the package checksums we know about, to get an Id
1129 we can use in a cache */
1130 stringpool_init_empty(&pd.cspool);
1132 XML_Parser parser = XML_ParserCreate(NULL);
1133 XML_SetUserData(parser, &pd);
1134 pd.parser = &parser;
1135 XML_SetElementHandler(parser, startElement, endElement);
1136 XML_SetCharacterDataHandler(parser, characterData);
1139 l = fread(buf, 1, sizeof(buf), fp);
1140 if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
1142 pool_debug(pool, SAT_FATAL, "repo_rpmmd: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
1148 XML_ParserFree(parser);
1149 sat_free(pd.content);
1151 stringpool_free(&pd.cspool);
1152 sat_free(pd.cscache);
1153 if (!(flags & REPO_NO_INTERNALIZE))
1154 repodata_internalize(data);
1155 POOL_DEBUG(SAT_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", sat_timems(now));
1156 POOL_DEBUG(SAT_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1157 POOL_DEBUG(SAT_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", data->incoredatalen/1024, repo->idarraysize / (int)(1024/sizeof(Id)));