static void startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts) { struct parsedata *pd = xmlp->userdata; Pool *pool = pd->pool; Solvable *s = pd->solvable; switch(state) { case STATE_PRODUCT: { /* parse 'type' */ const char *type = solv_xmlparser_find_attr("type", atts); s = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo)); pd->handle = s - pool->solvables; if (type) repodata_set_str(pd->data, pd->handle, PRODUCT_TYPE, type); } break; case STATE_VERSION: { const char *ver = solv_xmlparser_find_attr("ver", atts); const char *rel = solv_xmlparser_find_attr("rel", atts); /* const char *epoch = solv_xmlparser_find_attr("epoch", atts); ignored */ s->evr = makeevr(pd->pool, join2(&pd->jd, ver, "-", rel)); } break; case STATE_SUMMARY: /* <summary lang="xy">... */ pd->tmplang = join_dup(&pd->jd, solv_xmlparser_find_attr("lang", atts)); break; default: break; } }
static unsigned int adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id marker, char *kind) { int i, flags; Id id, evrid; char *sp[4]; if (line[6] == '/') { /* A file dependency. Do not try to parse it */ id = pool_str2id(pool, line + 6, 1); } #ifdef ENABLE_COMPLEX_DEPS else if (line[6] == '(') { id = pool_parserpmrichdep(pool, line + 6); if (!id) { pd->ret = pool_error(pool, -1, "susetags: line %d: bad dependency: '%s'\n", pd->lineno, line); return olddeps; } } #endif else { i = split(line + 6, sp, 4); /* name, <op>, evr, ? */ if (i != 1 && i != 3) /* expect either 'name' or 'name' <op> 'evr' */ { pd->ret = pool_error(pool, -1, "susetags: line %d: bad dependency: '%s'\n", pd->lineno, line); return olddeps; } if (kind) id = pool_str2id(pool, join2(&pd->jd, kind, ":", sp[0]), 1); else id = pool_str2id(pool, sp[0], 1); if (i == 3) { evrid = makeevr(pool, sp[2]); for (flags = 0; flags < 6; flags++) if (!strcmp(sp[1], flagtab[flags])) break; if (flags == 6) { if (!strcmp(sp[1], "<>")) flags = 4; else { pd->ret = pool_error(pool, -1, "susetags: line %d: unknown relation: '%s'\n", pd->lineno, sp[1]); return olddeps; } } id = pool_rel2id(pool, id, evrid, flags + 1, 1); } } return repo_addid_dep(pd->repo, olddeps, id, marker); }
int repo_add_content(Repo *repo, FILE *fp, int flags) { Pool *pool = repo->pool; char *line, *linep; int aline; Solvable *s; struct parsedata pd; Repodata *data; Id handle = 0; int contentstyle = 0; char *descrdir = 0; char *datadir = 0; char *defvendor = 0; int i = 0; int res = 0; /* architectures we use the first architecture in BASEARCHS or noarch for the product. At the end we create (clone) the product for each one of the remaining architectures we allow max 4 archs */ unsigned int numotherarchs = 0; Id *otherarchs = 0; memset(&pd, 0, sizeof(pd)); line = solv_malloc(1024); aline = 1024; pd.repo = repo; linep = line; s = 0; data = repo_add_repodata(repo, flags); for (;;) { char *key, *value; /* read line into big-enough buffer */ if (linep - line + 16 > aline) { aline = linep - line; line = solv_realloc(line, aline + 512); linep = line + aline; aline += 512; } if (!fgets(linep, aline - (linep - line), fp)) break; linep += strlen(linep); if (linep == line || linep[-1] != '\n') continue; while ( --linep > line && ( linep[-1] == ' ' || linep[-1] == '\t' ) ) ; /* skip trailing ws */ *linep = 0; linep = line; /* expect "key value" lines */ value = line; key = splitword(&value); if (key) { #if 0 fprintf (stderr, "key %s, value %s\n", key, value); #endif #define istag(x) (!strcmp (key, x)) #define code10 (contentstyle == 10) #define code11 (contentstyle == 11) if (istag ("CONTENTSTYLE")) { if (contentstyle) pool_debug(pool, SOLV_ERROR, "repo_content: 'CONTENTSTYLE' must be first line of 'content'\n"); contentstyle = atoi(value); continue; } if (!contentstyle) contentstyle = 10; /* repository tags */ /* we also replicate some of them into the product solvables * to be backward compatible */ if (istag ("REPOID")) { repodata_add_poolstr_array(data, SOLVID_META, REPOSITORY_REPOID, value); continue; } if (istag ("REPOKEYWORDS")) { add_multiple_strings(data, SOLVID_META, REPOSITORY_KEYWORDS, value); continue; } if (istag ("DISTRO")) { Id dh = repodata_new_handle(data); char *p; /* like with createrepo --distro */ if ((p = strchr(value, ',')) != 0) { *p++ = 0; if (*value) repodata_set_poolstr(data, dh, REPOSITORY_PRODUCT_CPEID, value); } else p = value; if (*p) repodata_set_str(data, dh, REPOSITORY_PRODUCT_LABEL, p); repodata_add_flexarray(data, SOLVID_META, REPOSITORY_DISTROS, dh); continue; } if (istag ("DESCRDIR")) { if (descrdir) free(descrdir); else repodata_set_str(data, SOLVID_META, SUSETAGS_DESCRDIR, value); if (s) repodata_set_str(data, s - pool->solvables, SUSETAGS_DESCRDIR, value); descrdir = solv_strdup(value); continue; } if (istag ("DATADIR")) { if (datadir) free(datadir); else repodata_set_str(data, SOLVID_META, SUSETAGS_DATADIR, value); if (s) repodata_set_str(data, s - pool->solvables, SUSETAGS_DATADIR, value); datadir = solv_strdup(value); continue; } if (istag ("VENDOR")) { if (defvendor) free(defvendor); else repodata_set_poolstr(data, SOLVID_META, SUSETAGS_DEFAULTVENDOR, value); if (s) s->vendor = pool_str2id(pool, value, 1); defvendor = solv_strdup(value); continue; } if (istag ("META") || istag ("HASH") || istag ("KEY")) { char *checksumtype, *checksum; Id fh, type; int l; if ((checksumtype = splitword(&value)) == 0) continue; if ((checksum = splitword(&value)) == 0) continue; if (!*value) continue; type = solv_chksum_str2type(checksumtype); if (!type) { pool_error(pool, -1, "%s: unknown checksum type '%s'", value, checksumtype); res = 1; continue; } l = solv_chksum_len(type); if (strlen(checksum) != 2 * l) { pool_error(pool, -1, "%s: invalid checksum length for %s", value, checksumtype); res = 1; continue; } fh = repodata_new_handle(data); repodata_set_poolstr(data, fh, SUSETAGS_FILE_TYPE, key); repodata_set_str(data, fh, SUSETAGS_FILE_NAME, value); repodata_set_checksum(data, fh, SUSETAGS_FILE_CHECKSUM, type, checksum); repodata_add_flexarray(data, SOLVID_META, SUSETAGS_FILE, fh); continue; } /* product tags */ if ((code10 && istag ("PRODUCT")) || (code11 && istag ("NAME"))) { if (s && !s->name) { /* this solvable was created without seeing a PRODUCT entry, just set the name and continue */ s->name = pool_str2id(pool, join(&pd, "product", ":", value), 1); continue; } if (s) { /* finish old solvable */ if (!s->arch) s->arch = ARCH_NOARCH; if (!s->evr) s->evr = ID_EMPTY; if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); if (code10) s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, 0); } /* create new solvable */ s = pool_id2solvable(pool, repo_add_solvable(repo)); handle = s - pool->solvables; s->name = pool_str2id(pool, join(&pd, "product", ":", value), 1); if (datadir) repodata_set_str(data, s - pool->solvables, SUSETAGS_DATADIR, datadir); if (descrdir) repodata_set_str(data, s - pool->solvables, SUSETAGS_DESCRDIR, descrdir); if (defvendor) s->vendor = pool_str2id(pool, defvendor, 1); continue; } /* Sometimes PRODUCT/NAME is not the first entry, but we need a solvable from here on. */ if (!s) { s = pool_id2solvable(pool, repo_add_solvable(repo)); handle = s - pool->solvables; } if (istag ("VERSION")) pd.tmpvers = solv_strdup(value); else if (istag ("RELEASE")) pd.tmprel = solv_strdup(value); else if (code11 && istag ("DISTRIBUTION")) repodata_set_poolstr(data, s - pool->solvables, SOLVABLE_DISTRIBUTION, value); else if (istag ("UPDATEURLS")) add_multiple_urls(data, handle, value, pool_str2id(pool, "update", 1)); else if (istag ("EXTRAURLS")) add_multiple_urls(data, handle, value, pool_str2id(pool, "extra", 1)); else if (istag ("OPTIONALURLS")) add_multiple_urls(data, handle, value, pool_str2id(pool, "optional", 1)); else if (istag ("RELNOTESURL")) add_multiple_urls(data, handle, value, pool_str2id(pool, "releasenotes", 1)); else if (istag ("SHORTLABEL")) repodata_set_str(data, s - pool->solvables, PRODUCT_SHORTLABEL, value); else if (istag ("LABEL")) /* LABEL is the products SUMMARY. */ repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, value); else if (!strncmp (key, "LABEL.", 6)) repodata_set_str(data, s - pool->solvables, pool_id2langid(pool, SOLVABLE_SUMMARY, key + 6, 1), value); else if (istag ("FLAGS")) add_multiple_strings(data, handle, PRODUCT_FLAGS, value); else if (istag ("VENDOR")) /* actually already handled above */ s->vendor = pool_str2id(pool, value, 1); else if (istag ("BASEARCHS")) { char *arch; if ((arch = splitword(&value)) != 0) { s->arch = pool_str2id(pool, arch, 1); while ((arch = splitword(&value)) != 0) { otherarchs = solv_extend(otherarchs, numotherarchs, 1, sizeof(Id), 7); otherarchs[numotherarchs++] = pool_str2id(pool, arch, 1); } } } if (!code10) continue; /* * Every tag below is Code10 only * */ if (istag ("ARCH")) /* Theoretically we want to have the best arch of the given modifiers which still is compatible with the system arch. We don't know the latter here, though. */ s->arch = ARCH_NOARCH; else if (istag ("PREREQUIRES")) s->requires = adddep(pool, &pd, s->requires, value, SOLVABLE_PREREQMARKER); else if (istag ("REQUIRES")) s->requires = adddep(pool, &pd, s->requires, value, -SOLVABLE_PREREQMARKER); else if (istag ("PROVIDES")) s->provides = adddep(pool, &pd, s->provides, value, 0); else if (istag ("CONFLICTS")) s->conflicts = adddep(pool, &pd, s->conflicts, value, 0); else if (istag ("OBSOLETES")) s->obsoletes = adddep(pool, &pd, s->obsoletes, value, 0); else if (istag ("RECOMMENDS")) s->recommends = adddep(pool, &pd, s->recommends, value, 0); else if (istag ("SUGGESTS")) s->suggests = adddep(pool, &pd, s->suggests, value, 0); else if (istag ("SUPPLEMENTS")) s->supplements = adddep(pool, &pd, s->supplements, value, 0); else if (istag ("ENHANCES")) s->enhances = adddep(pool, &pd, s->enhances, value, 0); /* FRESHENS doesn't seem to exist. */ else if (istag ("TYPE")) repodata_set_str(data, s - pool->solvables, PRODUCT_TYPE, value); /* XXX do something about LINGUAS and ARCH? * <ma>: Don't think so. zypp does not use or propagate them. */ #undef istag } else pool_debug(pool, SOLV_ERROR, "repo_content: malformed line: %s\n", line); } if (datadir) free(datadir); if (descrdir) free(descrdir); if (defvendor) free(defvendor); if (s && !s->name) { pool_debug(pool, SOLV_ERROR, "repo_content: 'content' incomplete, no product solvable created!\n"); repo_free_solvable(repo, s - pool->solvables, 1); s = 0; } if (s) { if (pd.tmprel) s->evr = makeevr(pool, join(&pd, pd.tmpvers, "-", pd.tmprel)); else s->evr = makeevr(pool, pd.tmpvers); pd.tmpvers = solv_free((void *)pd.tmpvers); pd.tmprel = solv_free((void *)pd.tmprel); if (!s->arch) s->arch = ARCH_NOARCH; if (!s->evr) s->evr = ID_EMPTY; if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); if (code10) s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, 0); /* now for every other arch, clone the product except the architecture */ for (i = 0; i < numotherarchs; ++i) { Solvable *p = pool_id2solvable(pool, repo_add_solvable(repo)); p->name = s->name; p->evr = s->evr; p->vendor = s->vendor; p->arch = otherarchs[i]; /* self provides */ if (s->name && p->arch != ARCH_SRC && p->arch != ARCH_NOSRC) p->provides = repo_addid_dep(repo, p->provides, pool_rel2id(pool, p->name, p->evr, REL_EQ, 1), 0); /* now merge the attributes */ repodata_merge_attrs(data, p - pool->solvables, s - pool->solvables); } } if (pd.tmp) solv_free(pd.tmp); solv_free(line); solv_free(otherarchs); if (!(flags & REPO_NO_INTERNALIZE)) repodata_internalize(data); return res; }
static void add_releasefile_product(Repo *repo, FILE *fp) { Pool *pool = repo->pool; char buf[BUFF_SIZE]; Id name = 0; Id arch = 0; Id version = 0; int lnum = 0; /* line number */ char *ptr, *ptr1; /* parse /etc/<xyz>-release file */ while (fgets(buf, sizeof(buf), fp)) { /* remove trailing \n */ int l = strlen(buf); if (l && buf[l - 1] == '\n') buf[--l] = 0; ++lnum; if (lnum == 1) { /* 1st line, <name> [(<arch>)] */ ptr = strchr(buf, '('); if (ptr) { ptr1 = ptr - 1; *ptr++ = 0; } else ptr1 = buf + l - 1; /* track back until non-blank, non-digit */ while (ptr1 > buf && (*ptr1 == ' ' || isdigit(*ptr1) || *ptr1 == '.')) --ptr1; *(++ptr1) = 0; name = pool_str2id(pool, join2("product", ":", buf), 1); if (ptr) { /* have arch */ char *ptr1 = strchr(ptr, ')'); if (ptr1) { *ptr1 = 0; /* downcase arch */ ptr1 = ptr; while (*ptr1) { if (isupper(*ptr1)) *ptr1 = tolower(*ptr1); ++ptr1; } arch = pool_str2id(pool, ptr, 1); } } } else if (strncmp(buf, "VERSION", 7) == 0) { ptr = strchr(buf + 7, '='); if (ptr) { while (*++ptr == ' ') ; version = makeevr(pool, ptr); } } } if (name) { Solvable *s = pool_id2solvable(pool, repo_add_solvable(repo)); s->name = name; s->evr = version ? version : ID_EMPTY; s->arch = arch ? arch : ARCH_NOARCH; if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0); } }
static void XMLCALL endElement(void *userData, const char *name) { struct parsedata *pd = userData; Solvable *s = pd->solvable; #if 0 fprintf(stderr, "end: [%d]%s\n", pd->state, name); #endif if (pd->depth != pd->statedepth) { pd->depth--; #if 0 fprintf(stderr, "back from unknown %d %d %d\n", pd->state, pd->depth, pd->statedepth); #endif return; } pd->depth--; pd->statedepth--; switch (pd->state) { case STATE_PRODUCT: /* product done, finish solvable */ if (pd->ctime) repodata_set_num(pd->data, pd->handle, SOLVABLE_INSTALLTIME, pd->ctime); if (pd->basename) repodata_set_str(pd->data, pd->handle, PRODUCT_REFERENCEFILE, pd->basename); /* this is where <productsdir>/baseproduct points to */ if (pd->currentproduct == pd->baseproduct) repodata_set_str(pd->data, pd->handle, PRODUCT_TYPE, "base"); if (pd->tmprel) { if (pd->tmpvers) s->evr = makeevr(pd->pool, join2(&pd->jd, pd->tmpvers, "-", pd->tmprel)); else { fprintf(stderr, "Seen <release> but no <version>\n"); } } else if (pd->tmpvers) s->evr = makeevr(pd->pool, pd->tmpvers); /* just version, no release */ pd->tmpvers = solv_free((void *)pd->tmpvers); pd->tmprel = solv_free((void *)pd->tmprel); if (!s->arch) s->arch = ARCH_NOARCH; if (!s->evr) s->evr = ID_EMPTY; if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC) s->provides = repo_addid_dep(pd->repo, s->provides, pool_rel2id(pd->pool, s->name, s->evr, REL_EQ, 1), 0); pd->solvable = 0; break; case STATE_VENDOR: s->vendor = pool_str2id(pd->pool, pd->content, 1); break; case STATE_NAME: s->name = pool_str2id(pd->pool, join2(&pd->jd, "product", ":", pd->content), 1); break; case STATE_VERSION: pd->tmpvers = solv_strdup(pd->content); break; case STATE_RELEASE: pd->tmprel = solv_strdup(pd->content); break; case STATE_ARCH: s->arch = pool_str2id(pd->pool, pd->content, 1); break; case STATE_PRODUCTLINE: repodata_set_str(pd->data, pd->handle, PRODUCT_PRODUCTLINE, pd->content); break; case STATE_UPDATEREPOKEY: /** obsolete **/ break; case STATE_SUMMARY: repodata_set_str(pd->data, pd->handle, pool_id2langid(pd->pool, SOLVABLE_SUMMARY, pd->tmplang, 1), pd->content); break; case STATE_SHORTSUMMARY: repodata_set_str(pd->data, pd->handle, PRODUCT_SHORTLABEL, pd->content); break; case STATE_DESCRIPTION: repodata_set_str(pd->data, pd->handle, pool_id2langid(pd->pool, SOLVABLE_DESCRIPTION, pd->tmplang, 1), pd->content); break; case STATE_URL: if (pd->urltype) { repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content); repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, pd->urltype); } break; case STATE_TARGET: repodata_set_str(pd->data, pd->handle, PRODUCT_REGISTER_TARGET, pd->content); break; case STATE_REGRELEASE: repodata_set_str(pd->data, pd->handle, PRODUCT_REGISTER_RELEASE, pd->content); break; case STATE_CPEID: if (*pd->content) repodata_set_str(pd->data, pd->handle, SOLVABLE_CPEID, pd->content); default: break; } pd->state = pd->sbtab[pd->state]; pd->docontent = 0; #if 0 fprintf(stderr, "end: [%s] -> %d\n", name, pd->state); #endif }
static void XMLCALL startElement(void *userData, const char *name, const char **atts) { struct parsedata *pd = userData; Pool *pool = pd->pool; Solvable *s = pd->solvable; struct stateswitch *sw; #if 0 fprintf(stderr, "start: [%d]%s\n", pd->state, name); #endif if (pd->depth != pd->statedepth) { pd->depth++; return; } pd->depth++; if (!pd->swtab[pd->state]) /* no statetable -> no substates */ { #if 0 fprintf(stderr, "into unknown: %s (from: %d)\n", name, pd->state); #endif return; } for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++) /* find name in statetable */ if (!strcmp(sw->ename, name)) break; if (sw->from != pd->state) { #if 0 fprintf(stderr, "into unknown: %s (from: %d)\n", name, pd->state); #endif return; } pd->state = sw->to; pd->docontent = sw->docontent; pd->statedepth = pd->depth; pd->lcontent = 0; *pd->content = 0; switch(pd->state) { case STATE_PRODUCT: { /* parse 'type' */ const char *type = find_attr("type", atts, 0); s = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo)); repodata_extend(pd->data, s - pool->solvables); pd->handle = s - pool->solvables; if (type) { repodata_set_str(pd->data, pd->handle, PRODUCT_TYPE, type); } } break; case STATE_VERSION: { const char *ver = find_attr("ver", atts, 0); const char *rel = find_attr("rel", atts, 0); /* const char *epoch = find_attr("epoch", atts, 1); ignored */ s->evr = makeevr(pd->pool, join2(ver, "-", rel)); } break; /* <summary lang="xy">... */ case STATE_SUMMARY: pd->tmplang = find_attr("lang", atts, 1); break; default: break; } }