#include "tools_util.h"
#include "repo_rpmmd.h"
#include "chksum.h"
-
+#ifdef ENABLE_COMPLEX_DEPS
+#include "pool_parserpmrichdep.h"
+#endif
enum state {
STATE_START,
STATE_ARCH,
STATE_VERSION,
- // package rpm-md
+ /* package rpm-md */
STATE_LOCATION,
STATE_CHECKSUM,
STATE_RPM_GROUP,
STATE_AFFECTSPKG,
STATE_REBOOTNEEDED,
- // pattern attributes
+ /* pattern attributes */
STATE_CATEGORY, /* pattern and patches */
+ STATE_ORDER,
+ STATE_INCLUDES,
+ STATE_INCLUDESENTRY,
+ STATE_EXTENDS,
+ STATE_EXTENDSENTRY,
STATE_SCRIPT,
STATE_ICON,
STATE_USERVISIBLE,
STATE_INSTALL_TIME,
/* product */
- STATE_SHORTNAME,
- STATE_DISTNAME, // obsolete
- STATE_DISTEDITION, // obsolete
- STATE_SOURCE,
- STATE_TYPE,
STATE_RELNOTESURL,
STATE_UPDATEURL,
STATE_OPTIONALURL,
STATE_FILE,
- // general
+ STATE_CHANGELOG,
+
+ /* general */
NUMSTATES
};
{ STATE_SOLVABLE, "arch", STATE_ARCH, 1 },
{ STATE_SOLVABLE, "version", STATE_VERSION, 0 },
- // package attributes rpm-md
+ /* package attributes rpm-md */
{ STATE_SOLVABLE, "location", STATE_LOCATION, 0 },
{ STATE_SOLVABLE, "checksum", STATE_CHECKSUM, 1 },
{ STATE_SOLVABLE, "distribution", STATE_DISTRIBUTION, 1 },
{ STATE_SOLVABLE, "url", STATE_URL, 1 },
{ STATE_SOLVABLE, "packager", STATE_PACKAGER, 1 },
- //{ STATE_SOLVABLE, "???", STATE_INSNOTIFY, 1 },
- //{ STATE_SOLVABLE, "??", STATE_DELNOTIFY, 1 },
{ STATE_SOLVABLE, "vendor", STATE_VENDOR, 1 },
{ STATE_SOLVABLE, "size", STATE_SIZE, 0 },
{ STATE_SOLVABLE, "archive-size", STATE_DOWNLOADSIZE, 1 },
{ STATE_SOLVABLE, "keyword", STATE_KEYWORD, 1 },
{ STATE_SOLVABLE, "diskusage", STATE_DISKUSAGE, 0 },
- // pattern attribute
+ /* pattern attribute */
{ STATE_SOLVABLE, "script", STATE_SCRIPT, 1 },
{ STATE_SOLVABLE, "icon", STATE_ICON, 1 },
{ STATE_SOLVABLE, "uservisible", STATE_USERVISIBLE, 1 },
{ STATE_SOLVABLE, "category", STATE_CATEGORY, 1 },
+ { STATE_SOLVABLE, "order", STATE_ORDER, 1 },
+ { STATE_SOLVABLE, "includes", STATE_INCLUDES, 0 },
+ { STATE_SOLVABLE, "extends", STATE_EXTENDS, 0 },
{ STATE_SOLVABLE, "default", STATE_DEFAULT, 1 },
{ STATE_SOLVABLE, "install-time", STATE_INSTALL_TIME, 1 },
/* product attributes */
/* note the product type is an attribute */
{ STATE_SOLVABLE, "release-notes-url", STATE_RELNOTESURL, 1 },
- { STATE_SOLVABLE, "update-url", STATE_UPDATEURL, 1 },
- { STATE_SOLVABLE, "optional-url", STATE_OPTIONALURL, 1 },
- { STATE_SOLVABLE, "flag", STATE_FLAG, 1 },
+ { STATE_SOLVABLE, "update-url", STATE_UPDATEURL, 1 },
+ { STATE_SOLVABLE, "optional-url", STATE_OPTIONALURL, 1 },
+ { STATE_SOLVABLE, "flag", STATE_FLAG, 1 },
- { STATE_SOLVABLE, "rpm:vendor", STATE_VENDOR, 1 },
- { STATE_SOLVABLE, "rpm:group", STATE_RPM_GROUP, 1 },
- { STATE_SOLVABLE, "rpm:license", STATE_RPM_LICENSE, 1 },
+ { STATE_SOLVABLE, "rpm:vendor", STATE_VENDOR, 1 },
+ { STATE_SOLVABLE, "rpm:group", STATE_RPM_GROUP, 1 },
+ { STATE_SOLVABLE, "rpm:license", STATE_RPM_LICENSE, 1 },
/* rpm-md dependencies */
- { STATE_SOLVABLE, "rpm:provides", STATE_PROVIDES, 0 },
- { STATE_SOLVABLE, "rpm:requires", STATE_REQUIRES, 0 },
- { STATE_SOLVABLE, "rpm:obsoletes", STATE_OBSOLETES, 0 },
- { STATE_SOLVABLE, "rpm:conflicts", STATE_CONFLICTS, 0 },
- { STATE_SOLVABLE, "rpm:recommends", STATE_RECOMMENDS , 0 },
- { STATE_SOLVABLE, "rpm:supplements", STATE_SUPPLEMENTS, 0 },
- { STATE_SOLVABLE, "rpm:suggests", STATE_SUGGESTS, 0 },
- { STATE_SOLVABLE, "rpm:enhances", STATE_ENHANCES, 0 },
- { STATE_SOLVABLE, "rpm:freshens", STATE_FRESHENS, 0 },
- { STATE_SOLVABLE, "rpm:sourcerpm", STATE_SOURCERPM, 1 },
- { STATE_SOLVABLE, "rpm:header-range", STATE_HEADERRANGE, 0 },
- { STATE_SOLVABLE, "file", STATE_FILE, 1 },
+ { STATE_SOLVABLE, "rpm:provides", STATE_PROVIDES, 0 },
+ { STATE_SOLVABLE, "rpm:requires", STATE_REQUIRES, 0 },
+ { STATE_SOLVABLE, "rpm:obsoletes", STATE_OBSOLETES, 0 },
+ { STATE_SOLVABLE, "rpm:conflicts", STATE_CONFLICTS, 0 },
+ { STATE_SOLVABLE, "rpm:recommends", STATE_RECOMMENDS , 0 },
+ { STATE_SOLVABLE, "rpm:supplements", STATE_SUPPLEMENTS, 0 },
+ { STATE_SOLVABLE, "rpm:suggests", STATE_SUGGESTS, 0 },
+ { STATE_SOLVABLE, "rpm:enhances", STATE_ENHANCES, 0 },
+ { STATE_SOLVABLE, "rpm:freshens", STATE_FRESHENS, 0 },
+ { STATE_SOLVABLE, "rpm:sourcerpm", STATE_SOURCERPM, 1 },
+ { STATE_SOLVABLE, "rpm:header-range", STATE_HEADERRANGE, 0 },
+ { STATE_SOLVABLE, "file", STATE_FILE, 1 },
+ { STATE_SOLVABLE, "changelog", STATE_CHANGELOG, 1 },
/* extended Novell/SUSE diskusage attributes (susedata.xml) */
{ STATE_DISKUSAGE, "dirs", STATE_DIRS, 0 },
{ STATE_ENHANCES, "rpm:entry", STATE_ENHANCESENTRY, 0 },
{ STATE_FRESHENS, "rpm:entry", STATE_FRESHENSENTRY, 0 },
+ { STATE_INCLUDES, "item", STATE_INCLUDESENTRY, 0 },
+ { STATE_EXTENDS, "item", STATE_EXTENDSENTRY, 0 },
+
{ NUMSTATES}
};
-/* maxmum initial size of
- the checksum cache */
-#define MAX_CSCACHE 32768
-#define CSREALLOC_STEP 1024
-
struct parsedata {
- struct parsedata_common common;
+ int ret;
+ Pool *pool;
+ Repo *repo;
+ Repodata *data;
char *kind;
int depth;
enum state state;
Offset freshens;
struct stateswitch *swtab[NUMSTATES];
enum state sbtab[NUMSTATES];
+ struct joindata jd;
/* temporal to store attribute tag language */
const char *tmplang;
- const char *capkind;
- // used to store tmp attributes
- // while the tag ends
- const char *tmpattr;
- Repodata *data;
+ Id chksumtype;
Id handle;
XML_Parser *parser;
- Id (*dirs)[3]; // dirid, size, nfiles
+ Id (*dirs)[3]; /* dirid, size, nfiles */
int ndirs;
- Id langcache[ID_NUM_INTERNAL];
- /** system language */
- const char *language;
+ const char *language; /* default language */
+ Id langcache[ID_NUM_INTERNAL]; /* cache for the default language */
Id lastdir;
char *lastdirstr;
int lastdirstrl;
- /** Hash to maps checksums to solv */
- Stringpool cspool;
- /** Cache of known checksums to solvable id */
- Id *cscache;
- /* the current longest index in the table */
- int ncscache;
+ Id changelog_handle;
+
+ int extending; /* are we extending an existing solvable? */
+ int first; /* first solvable we added */
+ int cshash_filled; /* hash is filled with data */
+
+ Hashtable cshash; /* checksum hash -> offset into csdata */
+ Hashval cshashm; /* hash mask */
+ int ncshash; /* entries used */
+ unsigned char *csdata; /* [len, checksum, id] */
+ int ncsdata; /* used bytes */
};
static Id
langtag(struct parsedata *pd, Id tag, const char *language)
{
- if (language && !language[0])
- language = 0;
- if (!language || tag >= ID_NUM_INTERNAL)
- return pool_id2langid(pd->common.repo->pool, tag, language, 1);
- return pool_id2langid(pd->common.repo->pool, tag, language, 1);
+ if (language)
+ {
+ if (!language[0] || !strcmp(language, "en"))
+ return tag;
+ return pool_id2langid(pd->pool, tag, language, 1);
+ }
+ if (!pd->language)
+ return tag;
+ if (tag >= ID_NUM_INTERNAL)
+ return pool_id2langid(pd->pool, tag, pd->language, 1);
if (!pd->langcache[tag])
- pd->langcache[tag] = pool_id2langid(pd->common.repo->pool, tag, language, 1);
+ pd->langcache[tag] = pool_id2langid(pd->pool, tag, pd->language, 1);
return pd->langcache[tag];
}
}
static void
-commit_diskusage (struct parsedata *pd, unsigned handle)
+commit_diskusage (struct parsedata *pd, Id handle)
{
- unsigned i;
+ int i;
Dirpool *dp = &pd->data->dirpool;
/* Now sort in dirid order. This ensures that parents come before
their children. */
if (pd->ndirs > 1)
- sat_sort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp, 0);
+ solv_sort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp, 0);
/* Substract leaf numbers from all parents to make the numbers
non-cumulative. This must be done post-order (i.e. all leafs
adjusted before parents). We ensure this by starting at the end of
the array moving to the start, hence seeing leafs before parents. */
for (i = pd->ndirs; i--;)
{
- unsigned p = dirpool_parent(dp, pd->dirs[i][0]);
- unsigned j = i;
+ Id p = dirpool_parent(dp, pd->dirs[i][0]);
+ int j = i;
for (; p; p = dirpool_parent(dp, p))
{
for (; j--;)
if (pd->dirs[j][0] == p)
break;
- if (j < pd->ndirs)
+ if (j >= 0)
{
if (pd->dirs[j][1] < pd->dirs[i][1])
pd->dirs[j][1] = 0;
else if (!strcmp(*atts, "rel"))
r = atts[1];
}
- if (e && !strcmp(e, "0"))
+ if (e && (!*e || !strcmp(e, "0")))
e = 0;
if (v && !e)
{
l += strlen(r) + 1;
if (l > pd->acontent)
{
- pd->content = sat_realloc(pd->content, l + 256);
+ pd->content = solv_realloc(pd->content, l + 256);
pd->acontent = l + 256;
}
c = pd->content;
#if 0
fprintf(stderr, "evr: %s\n", pd->content);
#endif
- return str2id(pool, pd->content, 1);
+ return pool_str2id(pool, pd->content, 1);
}
static unsigned int
adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts, int isreq)
{
- Id id, name, marker;
+ Id id, marker;
const char *n, *f, *k;
const char **a;
int l = strlen(k) + 1 + strlen(n) + 1;
if (l > pd->acontent)
{
- pd->content = sat_realloc(pd->content, l + 256);
+ pd->content = solv_realloc(pd->content, l + 256);
pd->acontent = l + 256;
}
sprintf(pd->content, "%s:%s", k, n);
- name = str2id(pool, pd->content, 1);
+ id = pool_str2id(pool, pd->content, 1);
+ }
+#ifdef ENABLE_COMPLEX_DEPS
+ else if (!f && n[0] == '(')
+ {
+ id = pool_parserpmrichdep(pool, n);
+ if (!id)
+ return olddeps;
}
+#endif
else
- name = str2id(pool, (char *)n, 1);
+ id = pool_str2id(pool, (char *)n, 1);
if (f)
{
Id evr = makeevr_atts(pool, pd, atts);
if (!strcmp(f, flagtab[flags]))
break;
flags = flags < 6 ? flags + 1 : 0;
- id = rel2id(pool, name, evr, flags, 1);
+ id = pool_rel2id(pool, id, evr, flags, 1);
}
- else
- id = name;
#if 0
- fprintf(stderr, "new dep %s%s%s\n", id2str(pool, d), id2rel(pool, d), id2evr(pool, d));
+ fprintf(stderr, "new dep %s\n", pool_dep2str(pool, id));
#endif
- return repo_addid_dep(pd->common.repo, olddeps, id, marker);
+ return repo_addid_dep(pd->repo, olddeps, id, marker);
}
/*
- * set_desciption_author
+ * set_description_author
*
*/
-
static void
-set_desciption_author(Repodata *data, Id handle, char *str)
+set_description_author(Repodata *data, Id handle, char *str, struct parsedata *pd)
{
char *aut, *p;
while (l > 0 && str[l - 1] == '\n')
str[--l] = 0;
if (l)
- repodata_set_str(data, handle, SOLVABLE_DESCRIPTION, str);
+ repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
p = aut + 19;
aut = str; /* copy over */
while (*p == ' ' || *p == '\n')
repodata_set_str(data, handle, SOLVABLE_AUTHORS, str);
}
else if (*str)
- repodata_set_str(data, handle, SOLVABLE_DESCRIPTION, str);
+ repodata_set_str(data, handle, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), str);
}
-/*
- * set_sourcerpm
+/*-----------------------------------------------*/
+/* checksum hash functions
+ *
+ * used to look up a solvable with the checksum for solvable extension purposes.
*
*/
static void
-set_sourcerpm(Repodata *data, Solvable *s, Id handle, char *sourcerpm)
+init_cshash(struct parsedata *pd)
{
- const char *p, *sevr, *sarch, *name, *evr;
- Pool *pool;
+}
- p = strrchr(sourcerpm, '.');
- if (!p || strcmp(p, ".rpm") != 0)
- return;
- p--;
- while (p > sourcerpm && *p != '.')
- p--;
- if (*p != '.' || p == sourcerpm)
- return;
- sarch = p-- + 1;
- while (p > sourcerpm && *p != '-')
- p--;
- if (*p != '-' || p == sourcerpm)
- return;
- p--;
- while (p > sourcerpm && *p != '-')
- p--;
- if (*p != '-' || p == sourcerpm)
+static void
+free_cshash(struct parsedata *pd)
+{
+ pd->cshash = solv_free(pd->cshash);
+ pd->ncshash = 0;
+ pd->cshashm = 0;
+ pd->csdata = solv_free(pd->csdata);
+ pd->ncsdata = 0;
+}
+
+static inline Hashval
+hashkey(const unsigned char *key, int keyl)
+{
+ return key[0] << 24 | key[1] << 16 | key[2] << 8 | key[3];
+}
+
+static void
+rebuild_cshash(struct parsedata *pd)
+{
+ Hashval h, hh, hm;
+ Hashtable ht;
+ unsigned char *d, *de;
+
+ hm = pd->cshashm;
+#if 0
+ fprintf(stderr, "rebuild cshash with mask 0x%x\n", hm);
+#endif
+ solv_free(pd->cshash);
+ ht = pd->cshash = (Hashtable)solv_calloc(hm + 1, sizeof(Id));
+ d = pd->csdata;
+ de = d + pd->ncsdata;
+ while (d != de)
+ {
+ h = hashkey(d + 1, d[0] + 1) & hm;
+ hh = HASHCHAIN_START;
+ while (ht[h])
+ h = HASHCHAIN_NEXT(h, hh, hm);
+ ht[h] = d + 1 - pd->csdata;
+ d += 2 + d[0] + sizeof(Id);
+ }
+}
+
+static void
+put_in_cshash(struct parsedata *pd, const unsigned char *key, int keyl, Id id)
+{
+ Hashtable ht;
+ Hashval h, hh, hm;
+ unsigned char *d;
+
+ if (keyl < 4 || keyl > 256)
return;
- sevr = p + 1;
- pool = s->repo->pool;
- if (!strcmp(sarch, "src.rpm"))
- repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_SRC);
- else if (!strcmp(sarch, "nosrc.rpm"))
- repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_NOSRC);
- else
- repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, strn2id(pool, sarch, strlen(sarch) - 4, 1));
- evr = id2str(pool, s->evr);
- if (evr && !strncmp(sevr, evr, sarch - sevr - 1) && evr[sarch - sevr - 1] == 0)
- repodata_set_void(data, handle, SOLVABLE_SOURCEEVR);
- else
- repodata_set_id(data, handle, SOLVABLE_SOURCEEVR, strn2id(pool, sevr, sarch - sevr - 1, 1));
- name = id2str(pool, s->name);
- if (name && !strncmp(sourcerpm, name, sevr - sourcerpm - 1) && name[sevr - sourcerpm - 1] == 0)
- repodata_set_void(data, handle, SOLVABLE_SOURCENAME);
+ ht = pd->cshash;
+ hm = pd->cshashm;
+ h = hashkey(key, keyl) & hm;
+ hh = HASHCHAIN_START;
+ if (ht)
+ {
+ while (ht[h])
+ {
+ unsigned char *d = pd->csdata + ht[h];
+ if (d[-1] == keyl - 1 && !memcmp(key, d, keyl))
+ return; /* XXX: first id wins... */
+ h = HASHCHAIN_NEXT(h, hh, hm);
+ }
+ }
+ /* a new entry. put in csdata */
+ pd->csdata = solv_extend(pd->csdata, pd->ncsdata, 1 + keyl + sizeof(Id), 1, 4095);
+ d = pd->csdata + pd->ncsdata;
+ d[0] = keyl - 1;
+ memcpy(d + 1, key, keyl);
+ memcpy(d + 1 + keyl, &id, sizeof(Id));
+ pd->ncsdata += 1 + keyl + sizeof(Id);
+ if ((Hashval)++pd->ncshash * 2 > hm)
+ {
+ pd->cshashm = pd->cshashm ? (2 * pd->cshashm + 1) : 4095;
+ rebuild_cshash(pd);
+ }
else
- repodata_set_id(data, handle, SOLVABLE_SOURCENAME, strn2id(pool, sourcerpm, sevr - sourcerpm - 1, 1));
+ ht[h] = pd->ncsdata - (keyl + sizeof(Id));
+}
+
+static Id
+lookup_cshash(struct parsedata *pd, const unsigned char *key, int keyl)
+{
+ Hashtable ht;
+ Hashval h, hh, hm;
+
+ if (keyl < 4 || keyl > 256)
+ return 0;
+ ht = pd->cshash;
+ if (!ht)
+ return 0;
+ hm = pd->cshashm;
+ h = hashkey(key, keyl) & hm;
+ hh = HASHCHAIN_START;
+ while (ht[h])
+ {
+ unsigned char *d = pd->csdata + ht[h];
+ if (d[-1] == keyl - 1 && !memcmp(key, d, keyl))
+ {
+ Id id;
+ memcpy(&id, d + keyl, sizeof(Id));
+ return id;
+ }
+ h = HASHCHAIN_NEXT(h, hh, hm);
+ }
+ return 0;
+}
+
+static void
+fill_cshash_from_repo(struct parsedata *pd)
+{
+ Dataiterator di;
+ /* setup join data */
+ dataiterator_init(&di, pd->pool, pd->repo, 0, SOLVABLE_CHECKSUM, 0, 0);
+ while (dataiterator_step(&di))
+ put_in_cshash(pd, (const unsigned char *)di.kv.str, solv_chksum_len(di.key->type), di.solvid);
+ dataiterator_free(&di);
+}
+
+static void
+fill_cshash_from_new_solvables(struct parsedata *pd)
+{
+ Pool *pool = pd->pool;
+ Id cstype = 0;
+ unsigned const char *cs;
+ int i;
+
+ for (i = pd->first; i < pool->nsolvables; i++)
+ {
+ if (pool->solvables[i].repo != pd->repo)
+ continue;
+ cs = repodata_lookup_bin_checksum_uninternalized(pd->data, i, SOLVABLE_CHECKSUM, &cstype);
+ if (cs)
+ put_in_cshash(pd, cs, solv_chksum_len(cstype), i);
+ }
}
/*-----------------------------------------------*/
static void XMLCALL
startElement(void *userData, const char *name, const char **atts)
{
- //fprintf(stderr,"+tag: %s\n", name);
struct parsedata *pd = userData;
- Pool *pool = pd->common.pool;
+ Pool *pool = pd->pool;
Solvable *s = pd->solvable;
struct stateswitch *sw;
const char *str;
Id handle = pd->handle;
+ const char *pkgid;
- // fprintf(stderr, "into %s, from %d, depth %d, statedepth %d\n", name, pd->state, pd->depth, pd->statedepth);
+ /* fprintf(stderr, "into %s, from %d, depth %d, statedepth %d\n", name, pd->state, pd->depth, pd->statedepth); */
if (pd->depth != pd->statedepth)
{
return;
if (pd->state == STATE_START && !strcmp(name, "products"))
return;
- //if (pd->state == STATE_START && !strcmp(name, "metadata"))
- // return;
+#if 0
+ if (pd->state == STATE_START && !strcmp(name, "metadata"))
+ return;
+#endif
if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
return;
pd->statedepth = pd->depth;
pd->lcontent = 0;
*pd->content = 0;
+
+ if (!s && pd->state != STATE_SOLVABLE)
+ return;
+
switch(pd->state)
{
case STATE_SOLVABLE:
a new solvable but just append the attributes to the existing
one.
*/
- const char *pkgid;
+ pd->extending = 0;
if ((pkgid = find_attr("pkgid", atts)) != NULL)
{
- // look at the checksum cache
- Id index = stringpool_str2id(&pd->cspool, pkgid, 0);
- if (!index || index >= pd->ncscache || !pd->cscache[index])
+ unsigned char chk[256];
+ int l;
+ const char *str = pkgid;
+ if (!pd->cshash_filled)
+ {
+ pd->cshash_filled = 1;
+ fill_cshash_from_new_solvables(pd);
+ }
+ handle = 0;
+ /* convert into bin checksum */
+ l = solv_hex2bin(&str, chk, sizeof(chk));
+ /* look at the checksum cache */
+ if (l >= 4 && !pkgid[2 * l])
+ handle = lookup_cshash(pd, chk, l);
+#if 0
+ fprintf(stderr, "Lookup %s -> %d\n", pkgid, handle);
+#endif
+ if (!handle)
{
- fprintf(stderr, "error, the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
- exit(1);
+ pool_debug(pool, SOLV_WARN, "the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
+ pd->handle = 0;
+ pd->solvable = 0;
+ break;
}
- pd->solvable = pool_id2solvable(pool, pd->cscache[index]);
+ pd->extending = 1;
}
- else
+ else
{
/* this is a new package */
- pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->common.repo));
+ handle = repo_add_solvable(pd->repo);
+ if (!pd->first)
+ pd->first = handle;
pd->freshens = 0;
}
- pd->handle = pd->solvable - pool->solvables;
+ pd->handle = handle;
+ pd->solvable = pool_id2solvable(pool, handle);
+ if (pd->kind && pd->kind[1] == 'r')
+ {
+ /* products can have a type */
+ const char *type = find_attr("type", atts);
+ if (type && *type)
+ repodata_set_str(pd->data, handle, PRODUCT_TYPE, type);
+ }
#if 0
fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
#endif
break;
case STATE_VERSION:
+ if (pd->extending && s->evr)
+ break; /* ignore version tag repetition in extend data */
s->evr = makeevr_atts(pool, pd, atts);
break;
case STATE_PROVIDES:
case STATE_FRESHENSENTRY:
pd->freshens = adddep(pool, pd, pd->freshens, atts, 0);
break;
+ case STATE_EULA:
case STATE_SUMMARY:
+ case STATE_CATEGORY:
case STATE_DESCRIPTION:
- pd->tmplang = find_attr("lang", atts);
+ pd->tmplang = join_dup(&pd->jd, find_attr("lang", atts));
break;
case STATE_USERVISIBLE:
- repodata_set_void(pd->data, handle, SOLVABLE_ISVISIBLE );
+ repodata_set_void(pd->data, handle, SOLVABLE_ISVISIBLE);
+ break;
+ case STATE_INCLUDESENTRY:
+ str = find_attr("pattern", atts);
+ if (str)
+ repodata_add_poolstr_array(pd->data, handle, SOLVABLE_INCLUDES, join2(&pd->jd, "pattern", ":", str));
+ break;
+ case STATE_EXTENDSENTRY:
+ str = find_attr("pattern", atts);
+ if (str)
+ repodata_add_poolstr_array(pd->data, handle, SOLVABLE_EXTENDS, join2(&pd->jd, "pattern", ":", str));
break;
case STATE_LOCATION:
str = find_attr("href", atts);
if (str)
- repodata_set_location(pd->data, handle, 0, 0, str);
+ {
+ int medianr = 0;
+ const char *base = find_attr("xml:base", atts);
+ if (base && !strncmp(base, "media:", 6))
+ {
+ /* check for the media number in the fragment */
+ int l = strlen(base);
+ while (l && base[l - 1] >= '0' && base[l - 1] <= '9')
+ l--;
+ if (l && base[l - 1] == '#' && base[l])
+ medianr = atoi(base + l);
+ }
+ repodata_set_location(pd->data, handle, medianr, 0, str);
+ if (base)
+ repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIABASE, base);
+ }
break;
case STATE_CHECKSUM:
- pd->tmpattr = find_attr("type", atts);
+ str = find_attr("type", atts);
+ pd->chksumtype = str && *str ? solv_chksum_str2type(str) : 0;
+ if (!pd->chksumtype)
+ pd->ret = pool_error(pool, -1, "line %d: unknown checksum type: %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), str ? str : "NULL");
break;
case STATE_TIME:
{
break;
}
case STATE_SIZE:
- {
- unsigned int k;
- str = find_attr("installed", atts);
- if (str && (k = atoi(str)) != 0)
- repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, (k + 1023) / 1024);
- /* XXX the "package" attribute gives the size of the rpm file,
- i.e. the download size. Except on packman, there it seems to be
- something else entirely, it has a value near to the other two
- values, as if the rpm is uncompressed. */
- str = find_attr("package", atts);
- if (str && (k = atoi(str)) != 0)
- repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, (k + 1023) / 1024);
- break;
- }
+ if ((str = find_attr("installed", atts)) != 0)
+ repodata_set_num(pd->data, handle, SOLVABLE_INSTALLSIZE, strtoull(str, 0, 10));
+ if ((str = find_attr("package", atts)) != 0)
+ repodata_set_num(pd->data, handle, SOLVABLE_DOWNLOADSIZE, strtoull(str, 0, 10));
+ break;
case STATE_HEADERRANGE:
{
unsigned int end;
str = find_attr("end", atts);
if (str && (end = atoi(str)) != 0)
repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
+ break;
}
/*
<diskusage>
*/
case STATE_DISKUSAGE:
{
- /* Really, do nothing, wat for <dir> tag */
+ /* Really, do nothing, wait for <dir> tag */
break;
}
case STATE_DIR:
{
long filesz = 0, filenum = 0;
- unsigned dirid;
- if ((str = find_attr("name", atts)) != 0)
- dirid = repodata_str2dir(pd->data, str, 1);
- else
- {
- fprintf( stderr, "<dir .../> tag without 'name' attribute, atts = %p, *atts = %p\n",
- (void *)atts, *atts);
+ Id dirid;
+ if ((str = find_attr("name", atts)) == 0)
+ {
+ pd->ret = pool_error(pool, -1, "<dir .../> tag without 'name' attribute");
break;
- }
+ }
+ if (*str != '/')
+ {
+ int l = strlen(str) + 2;
+ if (l > pd->acontent)
+ {
+ pd->content = solv_realloc(pd->content, l + 256);
+ pd->acontent = l + 256;
+ }
+ *pd->content = '/';
+ strcpy(pd->content + 1, str);
+ str = pd->content;
+ }
+ dirid = repodata_str2dir(pd->data, str, 1);
if ((str = find_attr("size", atts)) != 0)
filesz = strtol(str, 0, 0);
if ((str = find_attr("count", atts)) != 0)
filenum = strtol(str, 0, 0);
- pd->dirs = sat_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
+ pd->dirs = solv_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
pd->dirs[pd->ndirs][0] = dirid;
pd->dirs[pd->ndirs][1] = filesz;
pd->dirs[pd->ndirs][2] = filenum;
pd->ndirs++;
break;
}
+ case STATE_CHANGELOG:
+ pd->changelog_handle = repodata_new_handle(pd->data);
+ if ((str = find_attr("date", atts)) != 0)
+ repodata_set_num(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TIME, strtoull(str, 0, 10));
+ if ((str = find_attr("author", atts)) != 0)
+ repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_AUTHOR, str);
+ break;
default:
break;
}
static void XMLCALL
endElement(void *userData, const char *name)
{
- //fprintf(stderr,"-tag: %s\n", name);
struct parsedata *pd = userData;
- Pool *pool = pd->common.pool;
+ Pool *pool = pd->pool;
Solvable *s = pd->solvable;
- Repo *repo = pd->common.repo;
+ Repo *repo = pd->repo;
Id handle = pd->handle;
Id id;
char *p;
if (pd->depth != pd->statedepth)
{
pd->depth--;
- // printf("back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth);
+ /* printf("back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth); */
return;
}
return;
if (pd->state == STATE_START && !strcmp(name, "products"))
return;
- //if (pd->state == STATE_START && !strcmp(name, "metadata"))
- // return;
+#if 0
+ if (pd->state == STATE_START && !strcmp(name, "metadata"))
+ return;
+#endif
if (pd->state == STATE_SOLVABLE && !strcmp(name, "format"))
return;
pd->depth--;
pd->statedepth--;
+
+
+ if (!s)
+ {
+ pd->state = pd->sbtab[pd->state];
+ pd->docontent = 0;
+ return;
+ }
+
switch (pd->state)
{
case STATE_SOLVABLE:
+ if (pd->extending)
+ {
+ pd->solvable = 0;
+ break;
+ }
if (pd->kind && !s->name) /* add namespace in case of NULL name */
- s->name = str2id(pool, join2(pd->kind, ":", ""), 1);
+ s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", 0), 1);
if (!s->arch)
s->arch = ARCH_NOARCH;
if (!s->evr)
s->evr = ID_EMPTY; /* some patterns have this */
if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
- s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
- s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, pd->freshens);
- s->conflicts = repo_fix_conflicts(repo, s->conflicts);
+ s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
+ repo_rewrite_suse_deps(s, pd->freshens);
pd->freshens = 0;
pd->kind = 0;
+ pd->solvable = 0;
break;
case STATE_NAME:
if (pd->kind)
- s->name = str2id(pool, join2(pd->kind, ":", pd->content), 1);
+ s->name = pool_str2id(pool, join2(&pd->jd, pd->kind, ":", pd->content), 1);
else
- s->name = str2id(pool, pd->content, 1);
+ s->name = pool_str2id(pool, pd->content, 1);
break;
case STATE_ARCH:
- s->arch = str2id(pool, pd->content, 1);
+ s->arch = pool_str2id(pool, pd->content, 1);
break;
case STATE_VENDOR:
- s->vendor = str2id(pool, pd->content, 1);
+ s->vendor = pool_str2id(pool, pd->content, 1);
break;
case STATE_RPM_GROUP:
repodata_set_poolstr(pd->data, handle, SOLVABLE_GROUP, pd->content);
break;
case STATE_CHECKSUM:
{
- int l;
- Id type, index;
- if (!strcasecmp(pd->tmpattr, "sha") || !strcasecmp(pd->tmpattr, "sha1"))
- l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
- else if (!strcasecmp(pd->tmpattr, "sha256"))
- l = SIZEOF_SHA256 * 2, type = REPOKEY_TYPE_SHA256;
- else if (!strcasecmp(pd->tmpattr, "md5"))
- l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
- else
- {
- fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
- exit(1);
- }
- if (strlen(pd->content) != l)
- {
- fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), pd->tmpattr);
- exit(1);
- }
- repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, type, pd->content);
- /* we save the checksum to solvable id relationship for extended
- metadata */
- index = stringpool_str2id(&pd->cspool, pd->content, 1 /* create it */);
- if (index >= pd->ncscache)
+ unsigned char chk[256];
+ int l = solv_chksum_len(pd->chksumtype);
+ const char *str = pd->content;
+ if (!l || l > sizeof(chk))
+ break;
+ if (solv_hex2bin(&str, chk, l) != l || pd->content[2 * l])
{
- pd->cscache = sat_zextend(pd->cscache, pd->ncscache, index + 1 - pd->ncscache, sizeof(Id), 255);
- pd->ncscache = index + 1;
+ pd->ret = pool_error(pool, -1, "line %u: invalid %s checksum", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), solv_chksum_type2str(pd->chksumtype));
+ break;
}
- /* add the checksum to the cache */
- pd->cscache[index] = s - pool->solvables;
+ repodata_set_bin_checksum(pd->data, handle, SOLVABLE_CHECKSUM, pd->chksumtype, chk);
+ /* we save the checksum to solvable id relationship for extending metadata */
+ if (pd->cshash_filled)
+ put_in_cshash(pd, chk, l, s - pool->solvables);
break;
}
case STATE_FILE:
#if 0
- id = str2id(pool, pd->content, 1);
+ id = pool_str2id(pool, pd->content, 1);
s->provides = repo_addid_dep(repo, s->provides, id, SOLVABLE_FILEMARKER);
#endif
if ((p = strrchr(pd->content, '/')) != 0)
if (l > pd->lastdirstrl)
{
pd->lastdirstrl = l + 128;
- pd->lastdirstr = sat_realloc(pd->lastdirstr, pd->lastdirstrl);
+ pd->lastdirstr = solv_realloc(pd->lastdirstr, pd->lastdirstrl);
}
strcpy(pd->lastdirstr, pd->content);
pd->lastdir = id;
repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
break;
case STATE_SUMMARY:
- pd->tmplang = 0;
- repodata_set_str(pd->data, handle, SOLVABLE_SUMMARY, pd->content);
+ repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_SUMMARY, pd->tmplang), pd->content);
break;
case STATE_DESCRIPTION:
- pd->tmplang = 0;
- set_desciption_author(pd->data, handle, pd->content);
+ set_description_author(pd->data, handle, pd->content, pd);
+ break;
+ case STATE_CATEGORY:
+ repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_CATEGORY, pd->tmplang), pd->content);
break;
case STATE_DISTRIBUTION:
repodata_set_poolstr(pd->data, handle, SOLVABLE_DISTRIBUTION, pd->content);
repodata_set_poolstr(pd->data, handle, SOLVABLE_PACKAGER, pd->content);
break;
case STATE_SOURCERPM:
- set_sourcerpm(pd->data, s, handle, pd->content);
+ if (pd->content[0])
+ repodata_set_sourcepkg(pd->data, handle, pd->content);
break;
case STATE_RELNOTESURL:
if (pd->content[0])
{
- repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
- repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "releasenotes", 1));
+ repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
+ repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "releasenotes", 1));
}
break;
case STATE_UPDATEURL:
if (pd->content[0])
{
- repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
- repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "update", 1));
+ repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
+ repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "update", 1));
}
break;
case STATE_OPTIONALURL:
if (pd->content[0])
{
- repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
- repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "optional", 1));
+ repodata_add_poolstr_array(pd->data, handle, PRODUCT_URL, pd->content);
+ repodata_add_idarray(pd->data, handle, PRODUCT_URL_TYPE, pool_str2id(pool, "optional", 1));
}
break;
case STATE_FLAG:
if (pd->content[0])
- repodata_set_poolstr(pd->data, handle, PRODUCT_FLAGS, pd->content);
+ repodata_add_poolstr_array(pd->data, handle, PRODUCT_FLAGS, pd->content);
break;
case STATE_EULA:
if (pd->content[0])
- repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->language), pd->content);
+ repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->tmplang), pd->content);
break;
case STATE_KEYWORD:
if (pd->content[0])
- repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_KEYWORDS, pd->content);
+ repodata_add_poolstr_array(pd->data, handle, SOLVABLE_KEYWORDS, pd->content);
break;
case STATE_DISKUSAGE:
if (pd->ndirs)
- commit_diskusage(pd, pd->handle);
+ commit_diskusage(pd, handle);
+ break;
+ case STATE_ORDER:
+ if (pd->content[0])
+ repodata_set_str(pd->data, handle, SOLVABLE_ORDER, pd->content);
+ break;
+ case STATE_CHANGELOG:
+ repodata_set_str(pd->data, pd->changelog_handle, SOLVABLE_CHANGELOG_TEXT, pd->content);
+ repodata_add_flexarray(pd->data, handle, SOLVABLE_CHANGELOG, pd->changelog_handle);
+ pd->changelog_handle = 0;
break;
default:
break;
}
pd->state = pd->sbtab[pd->state];
pd->docontent = 0;
- // fprintf(stderr, "back from known %d %d %d\n", pd->state, pd->depth, pd->statedepth);
+ /* fprintf(stderr, "back from known %d %d %d\n", pd->state, pd->depth, pd->statedepth); */
}
l = pd->lcontent + len + 1;
if (l > pd->acontent)
{
- pd->content = sat_realloc(pd->content, l + 256);
+ pd->content = solv_realloc(pd->content, l + 256);
pd->acontent = l + 256;
}
c = pd->content + pd->lcontent;
*
*/
-void
+int
repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
{
Pool *pool = repo->pool;
struct stateswitch *sw;
Repodata *data;
unsigned int now;
+ XML_Parser parser;
- now = sat_timems(0);
+ now = solv_timems(0);
data = repo_add_repodata(repo, flags);
memset(&pd, 0, sizeof(pd));
pd.swtab[sw->from] = sw;
pd.sbtab[sw->to] = sw->from;
}
- pd.common.pool = pool;
- pd.common.repo = repo;
-
+ pd.pool = pool;
+ pd.repo = repo;
pd.data = data;
- pd.content = sat_malloc(256);
+ pd.content = solv_malloc(256);
pd.acontent = 256;
pd.lcontent = 0;
- pd.common.tmp = 0;
- pd.common.tmpl = 0;
pd.kind = 0;
- pd.language = language;
+ pd.language = language && *language && strcmp(language, "en") != 0 ? language : 0;
- /* initialize the string pool where we will store
- the package checksums we know about, to get an Id
- we can use in a cache */
- stringpool_init_empty(&pd.cspool);
+ init_cshash(&pd);
if ((flags & REPO_EXTEND_SOLVABLES) != 0)
{
/* setup join data */
- Dataiterator di;
- dataiterator_init(&di, pool, repo, 0, SOLVABLE_CHECKSUM, 0, 0);
- while (dataiterator_step(&di))
- {
- const char *str;
- int index;
-
- if (!sat_chksum_len(di.key->type))
- continue;
- str = repodata_chk2str(di.data, di.key->type, (const unsigned char *)di.kv.str);
- index = stringpool_str2id(&pd.cspool, str, 1);
- if (index >= pd.ncscache)
- {
- pd.cscache = sat_zextend(pd.cscache, pd.ncscache, index + 1 - pd.ncscache, sizeof(Id), 255);
- pd.ncscache = index + 1;
- }
- pd.cscache[index] = di.solvid;
- }
- dataiterator_free(&di);
+ pd.cshash_filled = 1;
+ fill_cshash_from_repo(&pd);
}
- XML_Parser parser = XML_ParserCreate(NULL);
+ parser = XML_ParserCreate(NULL);
XML_SetUserData(parser, &pd);
pd.parser = &parser;
XML_SetElementHandler(parser, startElement, endElement);
l = fread(buf, 1, sizeof(buf), fp);
if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
{
- 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));
- exit(1);
+ 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));
+ break;
}
if (l == 0)
break;
}
XML_ParserFree(parser);
- sat_free(pd.content);
- sat_free(pd.lastdirstr);
- join_freemem();
- stringpool_free(&pd.cspool);
- sat_free(pd.cscache);
-
+ solv_free(pd.content);
+ solv_free(pd.lastdirstr);
+ join_freemem(&pd.jd);
+ free_cshash(&pd);
+ repodata_free_dircache(data);
+
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
- POOL_DEBUG(SAT_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", sat_timems(now));
- POOL_DEBUG(SAT_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
- POOL_DEBUG(SAT_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", data->incoredatalen/1024, repo->idarraysize / (int)(1024/sizeof(Id)));
+ POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", solv_timems(now));
+ POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
+ 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)));
+ return pd.ret;
}