}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pool_debug(pd->pool, SOLV_ERROR, "repo_appdata: %s at line %u:%u\n", errstr, line, column);
- pd->ret = -1;
- if (pd->solvable)
- {
- repo_free_solvable(pd->repo, pd->solvable - pd->pool->solvables, 1);
- pd->solvable = 0;
- }
-}
-
static int
repo_add_appdata_fn(Repo *repo, FILE *fp, int flags, const char *filename, Queue *owners)
{
pd.filename = filename;
pd.owners = owners;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
- solv_xmlparser_parse(&pd.xmlp, fp);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ {
+ pool_debug(pd.pool, SOLV_ERROR, "repo_appdata: %s at line %u:%u\n", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
+ pd.ret = -1;
+ pd.solvable = solvable_free(pd.solvable, 1);
+ }
solv_xmlparser_free(&pd.xmlp);
solv_free(pd.desktop_file);
if (s && !s->name)
{
pool_error(pool, -1, "%s: package has no name", fn);
- repo_free_solvable(repo, s - pool->solvables, 1);
- s = 0;
+ s = solvable_free(s, 1);
}
if (s)
{
return;
if (!s->name)
{
- repo_free_solvable(repo, s - pool->solvables, 1);
+ solvable_free(s, 1);
return;
}
if (!s->arch)
}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pool_debug(pd->pool, SOLV_ERROR, "repo_comps: %s at line %u:%u\n", errstr, line, column);
-}
-
-
int
repo_add_comps(Repo *repo, FILE *fp, int flags)
{
pd.repo = repo;
pd.pool = repo->pool;
pd.data = data;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
- solv_xmlparser_parse(&pd.xmlp, fp);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ pool_debug(pd.pool, SOLV_ERROR, "repo_comps: %s at line %u:%u\n", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
solv_xmlparser_free(&pd.xmlp);
join_freemem(&pd.jd);
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;
+ s = solvable_free(s, 1);
}
if (s)
{
if (!*buf)
{
if (s && !repo && !isinstalled)
- {
- repo_free_solvable(repo, s - pool->solvables, 1);
- s = 0;
- }
+ s = solvable_free(s, 1);
if (s)
finishpackage(pool, s, keep, job);
s = 0;
{
isinstalled = 1;
if (!installedrepo)
- {
- repo_free_solvable(repo, s - pool->solvables, 1);
- s = 0;
- }
+ s = solvable_free(s, 1);
else if (s->repo != installedrepo)
{
copysolvabledata(pool, s, installedrepo);
}
}
if (s && !repo && !isinstalled)
- {
- repo_free_solvable(repo, s - pool->solvables, 1);
- s = 0;
- }
+ s = solvable_free(s, 1);
if (s)
finishpackage(pool, s, keep, job);
solv_free(buf);
s = pool_id2solvable(pool, repo_add_solvable(repo));
control2solvable(s, data, buf);
if (!s->name)
- repo_free_solvable(repo, s - pool->solvables, 1);
+ s = solvable_free(s, 1);
if (l > ll)
memmove(buf, p + 1, l - ll);
l -= ll;
s = pool_id2solvable(pool, repo_add_solvable(repo));
control2solvable(s, data, buf);
if (!s->name)
- repo_free_solvable(repo, s - pool->solvables, 1);
+ s = solvable_free(s, 1);
}
solv_free(buf);
if (!(flags & REPO_NO_INTERNALIZE))
}
}
-void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pd->ret = pool_error(pd->pool, -1, "repo_deltainfoxml: %s at line %u:%u", errstr, line, column);
-}
-
int
repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags)
{
pd.pool = pool;
pd.repo = repo;
pd.data = data;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
- solv_xmlparser_parse(&pd.xmlp, fp);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ pd.ret = pool_error(pd.pool, -1, "repo_deltainfoxml: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
solv_xmlparser_free(&pd.xmlp);
/* now commit all handles */
}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pd->ret = pool_error(pd->pool, -1, "%s at line %u", errstr, line);
-}
-
-
/*-------------------------------------------------------------------*/
/*
pd.pool = pool;
pd.repo = repo;
pd.data = data;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
pd.evrspace = (char *)solv_malloc(256);
pd.aevrspace = 256;
pd.levrspace = 1;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
- solv_xmlparser_parse(&pd.xmlp, fp);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ pd.ret = pool_error(pd.pool, -1, "repo_helix: %s at line %u", pd.xmlp.errstr, pd.xmlp.line);
solv_xmlparser_free(&pd.xmlp);
solv_free(pd.evrspace);
if (s)
{
pool_debug(pool, SOLV_ERROR, "unclosed package at EOF\n");
- repo_free_solvable(s->repo, s - pool->solvables, 1);
+ s = solvable_free(s, 1);
}
solv_free(buf);
if (!(flags & REPO_NO_INTERNALIZE))
}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pool_debug(pd->pool, SOLV_ERROR, "%s at line %u:%u\n", errstr, line, column);
-}
-
-
int
repo_add_mdk_info(Repo *repo, FILE *fp, int flags)
{
pd.repo = repo;
pd.pool = repo->pool;
pd.data = data;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
pd.joinhash = joinhash_init(repo, &pd.joinhashmask);
- solv_xmlparser_parse(&pd.xmlp, fp);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ pool_debug(pd.pool, SOLV_ERROR, "%s at line %u:%u\n", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
solv_xmlparser_free(&pd.xmlp);
solv_free(pd.joinhash);
if (!(flags & REPO_NO_INTERNALIZE))
}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pool_debug(pd->pool, SOLV_ERROR, "%s: %s at line %u:%u\n", pd->filename, errstr, line, column);
- if (pd->solvable)
- {
- repo_free_solvable(pd->repo, pd->solvable - pd->pool->solvables, 1);
- pd->solvable = 0;
- }
-}
-
-
int
repo_add_code11_products(Repo *repo, const char *dirpath, int flags)
{
pd.pool = repo->pool;
pd.data = data;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
if (flags & REPO_USE_ROOTDIR)
dirpath = pool_prepend_rootdir(repo->pool, dirpath);
pd.ctime = (unsigned int)st.st_ctime;
pd.filename = fullpath;
pd.basename = entry->d_name;
- solv_xmlparser_parse(&pd.xmlp, fp);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ {
+ pool_debug(pd.pool, SOLV_ERROR, "%s: %s at line %u:%u\n", pd.filename, pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
+ pd.solvable = solvable_free(pd.solvable, 1);
+ }
fclose(fp);
}
closedir(dir);
}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pd->ret = pool_error(pd->pool, -1, "repo_repomdxml: %s at line %u:%u", errstr, line, column);
-}
-
int
repo_add_repomdxml(Repo *repo, FILE *fp, int flags)
{
pd.pool = pool;
pd.repo = repo;
pd.data = data;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
-
- solv_xmlparser_parse(&pd.xmlp, fp);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ pd.ret = pool_error(pd.pool, -1, "repo_repomdxml: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
solv_xmlparser_free(&pd.xmlp);
if (!(flags & REPO_NO_INTERNALIZE))
if (s)
{
/* oops, could not reuse. free it instead */
- repo_free_solvable(repo, s - pool->solvables, 1);
+ s = solvable_free(s, 1);
solvend--;
- s = 0;
}
/* now sort all solvables in the new solvstart..solvend block */
if (solvend - solvstart > 1)
s = pool_id2solvable(pool, repo_add_solvable(repo));
if (!rpmhead2solv(pool, repo, data, s, state.rpmhead, flags & ~(RPM_ADD_WITH_HDRID | RPM_ADD_WITH_PKGID)))
{
- repo_free_solvable(repo, s - pool->solvables, 1);
+ s = solvable_free(s, 1);
solv_chksum_free(chksumh, 0);
headfree(state.rpmhead);
return 0;
s = pool_id2solvable(pool, repo_add_solvable(repo));
if (!rpmhead2solv(pool, repo, data, s, rpmhead, flags))
{
- repo_free_solvable(repo, s - pool->solvables, 1);
+ s = solvable_free(s, 1);
return 0;
}
if (!(flags & REPO_NO_INTERNALIZE))
}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pd->ret = pool_error(pd->pool, -1, "repo_rpmmd: %s at line %u:%u", errstr, line, column);
-}
-
/*-----------------------------------------------*/
fill_cshash_from_repo(&pd);
}
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
- solv_xmlparser_parse(&pd.xmlp, fp);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ pd.ret = pool_error(pool, -1, "repo_rpmmd: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
solv_xmlparser_free(&pd.xmlp);
solv_free(pd.lastdirstr);
}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pd->ret = pool_error(pd->pool, -1, "repo_updateinfoxml: %s at line %u:%u", errstr, line, column);
-}
-
int
repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
{
pd.pool = pool;
pd.repo = repo;
pd.data = data;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
solv_xmlparser_parse(&pd.xmlp, fp);
+ pd.ret = pool_error(pool, -1, "repo_updateinfoxml: %s at line %u:%u", pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
solv_xmlparser_free(&pd.xmlp);
join_freemem(&pd.jd);
}
}
-static void
-errorCallback(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
-{
- struct parsedata *pd = xmlp->userdata;
- pool_debug(pd->pool, SOLV_ERROR, "repo_zyppdb: %s: %s at line %u:%u\n", pd->filename, errstr, line, column);
- if (pd->solvable)
- {
- repo_free_solvable(pd->repo, pd->solvable - pd->pool->solvables, 1);
- pd->solvable = 0;
- }
-}
-
/*
* read all installed products
pd.repo = repo;
pd.pool = repo->pool;
pd.data = data;
- solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement, errorCallback);
+ solv_xmlparser_init(&pd.xmlp, stateswitches, &pd, startElement, endElement);
if (flags & REPO_USE_ROOTDIR)
dirpath = pool_prepend_rootdir(repo->pool, dirpath);
continue;
}
pd.filename = entry->d_name;
- solv_xmlparser_parse(&pd.xmlp, fp);
+ if (solv_xmlparser_parse(&pd.xmlp, fp) != SOLV_XMLPARSER_OK)
+ {
+ pool_debug(pd.pool, SOLV_ERROR, "repo_zyppdb: %s: %s at line %u:%u\n", pd.filename, pd.xmlp.errstr, pd.xmlp.line, pd.xmlp.column);
+ pd.solvable = solvable_free(pd.solvable, 1);
+ }
fclose(fp);
}
}
struct solv_xmlparser_element *elements,
void *userdata,
void (*startelement)(struct solv_xmlparser *, int state, const char *name, const char **atts),
- void (*endelement)(struct solv_xmlparser *, int state, char *content),
- void (*errorhandler)(struct solv_xmlparser *, const char *errstr, unsigned int line, unsigned int column))
+ void (*endelement)(struct solv_xmlparser *, int state, char *content))
{
int i, nstates, nelements;
struct solv_xmlparser_element *el;
xmlp->userdata = userdata;
xmlp->startelement = startelement;
xmlp->endelement = endelement;
- xmlp->errorhandler = errorhandler;
}
void
xmlp->elementhelper = solv_free(xmlp->elementhelper);
queue_free(&xmlp->elementq);
xmlp->content = solv_free(xmlp->content);
+ xmlp->errstr = solv_free(xmlp->errstr);
+}
+
+static void
+set_error(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column)
+{
+ solv_free(xmlp->errstr);
+ xmlp->errstr = solv_strdup(errstr);
+ xmlp->line = line;
+ xmlp->column = column;
}
#ifdef WITH_LIBXML2
xmlp->parser = 0;
}
-static xmlParserCtxtPtr create_parser_ctx(struct solv_xmlparser *xmlp, char *buf, int l)
+static xmlParserCtxtPtr
+create_parser_ctx(struct solv_xmlparser *xmlp, char *buf, int l)
{
xmlSAXHandler sax;
memset(&sax, 0, sizeof(sax));
xmlp->parser = create_parser_ctx(xmlp, buf, l2);
if (!xmlp->parser)
{
- xmlp->errorhandler(xmlp, "could not create parser", 0, 0);
+ set_error(xmlp, "could not create parser", 0, 0);
return 0;
}
buf += l2;
if (xmlParseChunk(xmlp->parser, buf, l, l == 0 ? 1 : 0))
{
xmlErrorPtr err = xmlCtxtGetLastError(xmlp->parser);
- xmlp->errorhandler(xmlp, err->message, err->line, err->int2);
+ set_error(xmlp, err->message, err->line, err->int2);
return 0;
}
return 1;
{
if (XML_Parse(xmlp->parser, buf, l, l == 0) == XML_STATUS_ERROR)
{
- unsigned int line = XML_GetCurrentLineNumber(xmlp->parser);
- unsigned int column = XML_GetCurrentColumnNumber(xmlp->parser);
- xmlp->errorhandler(xmlp, XML_ErrorString(XML_GetErrorCode(xmlp->parser)), line, column);
+ set_error(xmlp, XML_ErrorString(XML_GetErrorCode(xmlp->parser)), XML_GetCurrentLineNumber(xmlp->parser), XML_GetCurrentColumnNumber(xmlp->parser));
return 0;
}
return 1;
#endif
-void
+int
solv_xmlparser_parse(struct solv_xmlparser *xmlp, FILE *fp)
{
char buf[8192];
- int l;
+ int l, ret = SOLV_XMLPARSER_OK;
xmlp->state = 0;
xmlp->unknowncnt = 0;
if (!create_parser(xmlp))
{
- xmlp->errorhandler(xmlp, "could not create xml parser", 0, 0);
- return;
+ set_error(xmlp, "could not create parser", 0, 0);
+ return SOLV_XMLPARSER_ERROR;
}
for (;;)
{
l = fread(buf, 1, sizeof(buf), fp);
if (!parse_block(xmlp, buf, l) || !l)
- break;
+ {
+ ret = SOLV_XMLPARSER_ERROR;
+ break;
+ }
}
free_parser(xmlp);
+ return ret;
}
char *
struct solv_xmlparser {
void *userdata;
+ char *errstr;
+ unsigned int line;
+ unsigned int column;
int state;
int docontent;
void (*startelement)(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts);
void (*endelement)(struct solv_xmlparser *xmlp, int state, char *content);
- void (*errorhandler)(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column);
Id *elementhelper;
void *parser;
};
+#define SOLV_XMLPARSER_OK 0
+#define SOLV_XMLPARSER_ERROR -1
+
static inline const char *
solv_xmlparser_find_attr(const char *txt, const char **atts)
{
extern void solv_xmlparser_init(struct solv_xmlparser *xmlp, struct solv_xmlparser_element *elements, void *userdata,
void (*startelement)(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts),
- void (*endelement)(struct solv_xmlparser *xmlp, int state, char *content),
- void (*errorhandler)(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column));
+ void (*endelement)(struct solv_xmlparser *xmlp, int state, char *content));
extern void solv_xmlparser_free(struct solv_xmlparser *xmlp);
-extern void solv_xmlparser_parse(struct solv_xmlparser *xmlp, FILE *fp);
+extern int solv_xmlparser_parse(struct solv_xmlparser *xmlp, FILE *fp);
unsigned int solv_xmlparser_lineno(struct solv_xmlparser *xmlp);
char *solv_xmlparser_contentspace(struct solv_xmlparser *xmlp, int l);