* for further information
*/
+#define _GNU_SOURCE
+#define _XOPEN_SOURCE
+#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <errno.h>
#include <limits.h>
#include <fcntl.h>
#include <ctype.h>
#include "tools_util.h"
#include "repo_content.h"
#include "repo_zyppdb.h"
+#include "repo_products.h"
#include "repo_releasefile_products.h"
-//#define DUMPOUT 0
-
enum state {
- STATE_START, // 0
- STATE_PRODUCT, // 1
- STATE_VENDOR, // 2
- STATE_NAME, // 3
- STATE_VERSION, // 4
- STATE_RELEASE, // 5
- STATE_ARCH, // 6
- STATE_SUMMARY, // 7
- STATE_DESCRIPTION, // 8
- STATE_UPDATEREPOKEY, // 9 should go away
- STATE_CPEID, // 9
- STATE_URLS, // 10
- STATE_URL, // 11
- STATE_RUNTIMECONFIG, // 12
- STATE_LINGUAS, // 13
- STATE_LANG, // 14
- STATE_REGISTER, // 15
- STATE_TARGET, // 16
- STATE_REGRELEASE, // 18
- STATE_PRODUCTLINE, // 19
- NUMSTATES // 0
+ STATE_START,
+ STATE_PRODUCT,
+ STATE_VENDOR,
+ STATE_NAME,
+ STATE_VERSION,
+ STATE_RELEASE,
+ STATE_ARCH,
+ STATE_SUMMARY,
+ STATE_SHORTSUMMARY,
+ STATE_DESCRIPTION,
+ STATE_UPDATEREPOKEY,
+ STATE_CPEID,
+ STATE_URLS,
+ STATE_URL,
+ STATE_RUNTIMECONFIG,
+ STATE_LINGUAS,
+ STATE_LANG,
+ STATE_REGISTER,
+ STATE_TARGET,
+ STATE_REGRELEASE,
+ STATE_REGFLAVOR,
+ STATE_PRODUCTLINE,
+ STATE_REGUPDATES,
+ STATE_REGUPDREPO,
+ STATE_ENDOFLIFE,
+ NUMSTATES
};
struct stateswitch {
{ STATE_PRODUCT, "arch", STATE_ARCH, 1 },
{ STATE_PRODUCT, "productline", STATE_PRODUCTLINE, 1 },
{ STATE_PRODUCT, "summary", STATE_SUMMARY, 1 },
+ { STATE_PRODUCT, "shortsummary", STATE_SHORTSUMMARY, 1 },
{ STATE_PRODUCT, "description", STATE_DESCRIPTION, 1 },
{ STATE_PRODUCT, "register", STATE_REGISTER, 0 },
{ STATE_PRODUCT, "urls", STATE_URLS, 0 },
{ STATE_PRODUCT, "linguas", STATE_LINGUAS, 0 },
{ STATE_PRODUCT, "updaterepokey", STATE_UPDATEREPOKEY, 1 },
{ STATE_PRODUCT, "cpeid", STATE_CPEID, 1 },
+ { STATE_PRODUCT, "endoflife", STATE_ENDOFLIFE, 1 },
{ STATE_URLS, "url", STATE_URL, 1 },
{ STATE_LINGUAS, "lang", STATE_LANG, 0 },
{ STATE_REGISTER, "target", STATE_TARGET, 1 },
{ STATE_REGISTER, "release", STATE_REGRELEASE, 1 },
+ { STATE_REGISTER, "flavor", STATE_REGFLAVOR, 1 },
+ { STATE_REGISTER, "updates", STATE_REGUPDATES, 0 },
+ { STATE_REGUPDATES, "repository", STATE_REGUPDREPO, 0 },
{ NUMSTATES }
};
struct stateswitch *swtab[NUMSTATES];
enum state sbtab[NUMSTATES];
+ struct joindata jd;
const char *tmplang;
const char *tmpvers;
const char *tmprel;
- const char *tmpurltype;
+ Id urltype;
unsigned int ctime;
ino_t baseproduct;
ino_t currentproduct;
int productscheme;
-
- Id langcache[ID_NUM_INTERNAL];
};
* find value for xml attribute
* I: txt, name of attribute
* I: atts, list of key/value attributes
- * I: dup, strdup it
* O: pointer to value of matching key, or NULL
*
*/
static inline const char *
-find_attr(const char *txt, const char **atts, int dup)
+find_attr(const char *txt, const char **atts)
{
for (; *atts; atts += 2)
{
if (!strcmp(*atts, txt))
- return dup ? strdup(atts[1]) : atts[1];
+ return atts[1];
}
return 0;
}
-
-/*
- * create localized tag
- */
-
-static Id
-langtag(struct parsedata *pd, Id tag, const char *language)
+static time_t
+datestr2timestamp(const char *date)
{
- if (language && !language[0])
- language = 0;
- if (!language || tag >= ID_NUM_INTERNAL)
- return pool_id2langid(pd->repo->pool, tag, language, 1);
- if (!pd->langcache[tag])
- pd->langcache[tag] = pool_id2langid(pd->repo->pool, tag, language, 1);
- return pd->langcache[tag];
+ const char *p;
+ struct tm tm;
+
+ if (!date || !*date)
+ return 0;
+ for (p = date; *p >= '0' && *p <= '9'; p++)
+ ;
+ if (!*p)
+ return atoi(date);
+ memset(&tm, 0, sizeof(tm));
+ p = strptime(date, "%F%T", &tm);
+ if (!p)
+ {
+ memset(&tm, 0, sizeof(tm));
+ p = strptime(date, "%F", &tm);
+ if (!p || *p)
+ return 0;
+ }
+ return timegm(&tm);
}
-
/*
* XML callback: startElement
*/
struct stateswitch *sw;
#if 0
- fprintf(stderr, "start: [%d]%s\n", pd->state, name);
+ fprintf(stderr, "start: [%d]%s\n", pd->state, name);
#endif
if (pd->depth != pd->statedepth)
{
case STATE_PRODUCT:
/* parse 'schemeversion' and store in global variable */
{
- const char * scheme = find_attr("schemeversion", atts, 0);
+ const char * scheme = find_attr("schemeversion", atts);
pd->productscheme = (scheme && *scheme) ? atoi(scheme) : -1;
}
if (!s)
/* <summary lang="xy">... */
case STATE_SUMMARY:
- pd->tmplang = find_attr("lang", atts, 1);
- break;
case STATE_DESCRIPTION:
- pd->tmplang = find_attr("lang", atts, 1);
+ pd->tmplang = join_dup(&pd->jd, find_attr("lang", atts));
break;
case STATE_URL:
- pd->tmpurltype = find_attr("name", atts, 1);
+ pd->urltype = pool_str2id(pd->pool, find_attr("name", atts), 1);
break;
+ case STATE_REGUPDREPO:
+ {
+ const char *repoid = find_attr("repoid", atts);
+ if (repoid && *repoid)
+ {
+ Id h = repodata_new_handle(pd->data);
+ repodata_set_str(pd->data, h, PRODUCT_UPDATES_REPOID, repoid);
+ repodata_add_flexarray(pd->data, pd->handle, PRODUCT_UPDATES, h);
+ }
+ break;
+ }
default:
break;
}
Solvable *s = pd->solvable;
#if 0
- fprintf(stderr, "end: [%d]%s\n", pd->state, name);
+ fprintf(stderr, "end: [%d]%s\n", pd->state, name);
#endif
if (pd->depth != pd->statedepth)
{
if (pd->tmprel)
{
if (pd->tmpvers)
- s->evr = makeevr(pd->pool, join2(pd->tmpvers, "-", pd->tmprel));
+ 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 = sat_free((void *)pd->tmpvers);
- pd->tmprel = sat_free((void *)pd->tmprel);
+ pd->tmpvers = solv_free((void *)pd->tmpvers);
+ pd->tmprel = solv_free((void *)pd->tmprel);
if (!s->arch)
s->arch = ARCH_NOARCH;
- if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
- s->provides = repo_addid_dep(pd->repo, s->provides, rel2id(pd->pool, s->name, s->evr, REL_EQ, 1), 0);
+ 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 = str2id(pd->pool, pd->content, 1);
+ s->vendor = pool_str2id(pd->pool, pd->content, 1);
break;
case STATE_NAME:
- s->name = str2id(pd->pool, join2("product", ":", pd->content), 1);
+ s->name = pool_str2id(pd->pool, join2(&pd->jd, "product", ":", pd->content), 1);
break;
case STATE_VERSION:
- pd->tmpvers = strdup(pd->content);
+ pd->tmpvers = solv_strdup(pd->content);
break;
case STATE_RELEASE:
- pd->tmprel = strdup(pd->content);
+ pd->tmprel = solv_strdup(pd->content);
break;
case STATE_ARCH:
- s->arch = str2id(pd->pool, pd->content, 1);
+ s->arch = pool_str2id(pd->pool, pd->content, 1);
break;
case STATE_PRODUCTLINE:
repodata_set_str(pd->data, pd->handle, PRODUCT_PRODUCTLINE, pd->content);
/** obsolete **/
break;
case STATE_SUMMARY:
- repodata_set_str(pd->data, pd->handle, langtag(pd, SOLVABLE_SUMMARY, pd->tmplang), pd->content);
- pd->tmplang = sat_free((void *)pd->tmplang);
+ 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, langtag(pd, SOLVABLE_DESCRIPTION, pd->tmplang), pd->content );
- pd->tmplang = sat_free((void *)pd->tmplang);
+ repodata_set_str(pd->data, pd->handle, pool_id2langid(pd->pool, SOLVABLE_DESCRIPTION, pd->tmplang, 1), pd->content);
break;
case STATE_URL:
- if (pd->tmpurltype)
+ 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, str2id(pd->pool, pd->tmpurltype, 1));
+ repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, pd->urltype);
}
- pd->tmpurltype = sat_free((void *)pd->tmpurltype);
break;
case STATE_TARGET:
repodata_set_str(pd->data, pd->handle, PRODUCT_REGISTER_TARGET, pd->content);
case STATE_REGRELEASE:
repodata_set_str(pd->data, pd->handle, PRODUCT_REGISTER_RELEASE, pd->content);
break;
+ case STATE_REGFLAVOR:
+ repodata_set_str(pd->data, pd->handle, PRODUCT_REGISTER_FLAVOR, pd->content);
+ break;
case STATE_CPEID:
- if (pd->content)
- repodata_set_str(pd->data, pd->handle, SOLVABLE_CPE_ID, pd->content);
+ if (*pd->content)
+ repodata_set_str(pd->data, pd->handle, SOLVABLE_CPEID, pd->content);
+ break;
+ case STATE_ENDOFLIFE:
+ /* FATE#320699: Support tri-state product-endoflife (tag absent, present but nodate(0), present + date) */
+ repodata_set_num(pd->data, pd->handle, PRODUCT_ENDOFLIFE, (*pd->content ? datestr2timestamp(pd->content) : 0));
+ break;
default:
break;
}
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;
char buf[BUFF_SIZE];
int l;
struct stat st;
+ XML_Parser parser;
if (!fstat(fileno(fp), &st))
{
else
{
pd->currentproduct = pd->baseproduct + 1; /* make it != baseproduct if stat fails */
- perror("fstat");
+ pool_error(pd->pool, 0, "fstat: %s", strerror(errno));
pd->ctime = 0;
}
- XML_Parser parser = XML_ParserCreate(NULL);
+ parser = XML_ParserCreate(NULL);
XML_SetUserData(parser, pd);
XML_SetElementHandler(parser, startElement, endElement);
XML_SetCharacterDataHandler(parser, characterData);
l = fread(buf, 1, sizeof(buf), fp);
if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
{
- pool_debug(pd->pool, SAT_ERROR, "%s: %s at line %u:%u\n", pd->filename, XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
- pool_debug(pd->pool, SAT_ERROR, "skipping this product\n");
+ pool_debug(pd->pool, SOLV_ERROR, "%s: %s at line %u:%u\n", pd->filename, XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
XML_ParserFree(parser);
+ if (pd->solvable)
+ {
+ repo_free_solvable(pd->repo, pd->solvable - pd->pool->solvables, 1);
+ pd->solvable = 0;
+ }
return;
}
if (l == 0)
}
-void
+int
repo_add_code11_products(Repo *repo, const char *dirpath, int flags)
{
Repodata *data;
DIR *dir;
int i;
- if (!(flags & REPO_REUSE_REPODATA))
- data = repo_add_repodata(repo, 0);
- else
- data = repo_last_repodata(repo);
+ data = repo_add_repodata(repo, flags);
memset(&pd, 0, sizeof(pd));
pd.repo = repo;
pd.pool = repo->pool;
pd.data = data;
- pd.content = sat_malloc(256);
+ pd.content = solv_malloc(256);
pd.acontent = 256;
for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
pd.sbtab[sw->to] = sw->from;
}
+ if (flags & REPO_USE_ROOTDIR)
+ dirpath = pool_prepend_rootdir(repo->pool, dirpath);
dir = opendir(dirpath);
if (dir)
{
char *fullpath;
/* check for <productsdir>/baseproduct on code11 and remember its target inode */
- if (stat(join2(dirpath, "/", "baseproduct"), &st) == 0) /* follow symlink */
+ if (stat(join2(&pd.jd, dirpath, "/", "baseproduct"), &st) == 0) /* follow symlink */
pd.baseproduct = st.st_ino;
else
pd.baseproduct = 0;
while ((entry = readdir(dir)))
{
int len = strlen(entry->d_name);
+ FILE *fp;
if (len <= 5 || strcmp(entry->d_name + len - 5, ".prod") != 0)
continue;
- fullpath = join2(dirpath, "/", entry->d_name);
- FILE *fp = fopen(fullpath, "r");
+ fullpath = join2(&pd.jd, dirpath, "/", entry->d_name);
+ fp = fopen(fullpath, "r");
if (!fp)
{
- perror(fullpath);
+ pool_error(repo->pool, 0, "%s: %s", fullpath, strerror(errno));
continue;
}
pd.filename = fullpath;
}
closedir(dir);
}
- sat_free((void *)pd.tmplang);
- sat_free(pd.content);
- join_freemem();
+ solv_free(pd.content);
+ join_freemem(&pd.jd);
+ if (flags & REPO_USE_ROOTDIR)
+ solv_free((char *)dirpath);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
+ return 0;
}
/* Oh joy! Three parsers for the price of one! */
-void
-repo_add_products(Repo *repo, const char *proddir, const char *root, int flags)
+int
+repo_add_products(Repo *repo, const char *proddir, int flags)
{
const char *fullpath;
DIR *dir;
- dir = opendir(proddir);
- if (dir)
+ if (proddir)
{
- /* assume code11 stype products */
- closedir(dir);
- repo_add_code11_products(repo, proddir, flags);
- return;
+ dir = opendir(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(repo->pool, proddir) : proddir);
+ if (dir)
+ {
+ /* assume code11 stype products */
+ closedir(dir);
+ return repo_add_code11_products(repo, proddir, flags);
+ }
}
- /* code11 didn't work, try old zyppdb */
- fullpath = root ? join2(root, "", "/var/lib/zypp/db/products") : "/var/lib/zypp/db/products";
+ /* code11 didn't work, try old code10 zyppdb */
+ fullpath = "/var/lib/zypp/db/products";
+ if (flags & REPO_USE_ROOTDIR)
+ fullpath = pool_prepend_rootdir_tmp(repo->pool, fullpath);
dir = opendir(fullpath);
if (dir)
{
closedir(dir);
/* assume code10 style products */
- repo_add_zyppdb_products(repo, fullpath, flags);
- join_freemem();
- return;
+ return repo_add_zyppdb_products(repo, "/var/lib/zypp/db/products", flags);
}
-
- /* code11 didn't work, try -release files parsing */
- fullpath = root ? join2(root, "", "/etc") : "/etc";
+
+ /* code10/11 didn't work, try -release files parsing */
+ fullpath = "/etc";
+ if (flags & REPO_USE_ROOTDIR)
+ fullpath = pool_prepend_rootdir_tmp(repo->pool, fullpath);
dir = opendir(fullpath);
if (dir)
{
closedir(dir);
- repo_add_releasefile_products(repo, fullpath, flags);
- join_freemem();
- return;
+ return repo_add_releasefile_products(repo, "/etc", flags);
+ }
+
+ /* no luck. check if the rootdir exists */
+ fullpath = pool_get_rootdir(repo->pool);
+ if (fullpath && *fullpath)
+ {
+ dir = opendir(fullpath);
+ if (!dir)
+ return pool_error(repo->pool, -1, "%s: %s", fullpath, strerror(errno));
+ closedir(dir);
}
- /* no luck. print an error message in case the root argument is wrong */
- perror(fullpath);
- join_freemem();
+ /* the least we can do... */
+ if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0)
+ repodata_internalize(repo_last_repodata(repo));
+ return 0;
}
/* EOF */