mirror of
https://github.com/openSUSE/libsolv.git
synced 2026-02-05 12:45:46 +01:00
Get rid of the xmlparser's error callback
It's much simpler to just return an error from the parse call.
This commit is contained in:
@@ -420,19 +420,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -448,8 +435,13 @@ repo_add_appdata_fn(Repo *repo, FILE *fp, int flags, const char *filename, Queue
|
||||
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);
|
||||
|
||||
@@ -444,8 +444,7 @@ repo_add_arch_pkg(Repo *repo, const char *fn, int flags)
|
||||
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)
|
||||
{
|
||||
@@ -728,7 +727,7 @@ finishsolvable(Repo *repo, Solvable *s)
|
||||
return;
|
||||
if (!s->name)
|
||||
{
|
||||
repo_free_solvable(repo, s - pool->solvables, 1);
|
||||
solvable_free(s, 1);
|
||||
return;
|
||||
}
|
||||
if (!s->arch)
|
||||
|
||||
@@ -206,14 +206,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -226,8 +218,9 @@ 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);
|
||||
|
||||
|
||||
@@ -517,8 +517,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -224,10 +224,7 @@ repo_add_cudf(Repo *repo, Repo *installedrepo, FILE *fp, Queue *job, int flags)
|
||||
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;
|
||||
@@ -323,10 +320,7 @@ repo_add_cudf(Repo *repo, Repo *installedrepo, FILE *fp, Queue *job, int flags)
|
||||
{
|
||||
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);
|
||||
@@ -371,10 +365,7 @@ repo_add_cudf(Repo *repo, Repo *installedrepo, FILE *fp, Queue *job, int flags)
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -499,7 +499,7 @@ repo_add_debpackages(Repo *repo, FILE *fp, int flags)
|
||||
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;
|
||||
@@ -511,7 +511,7 @@ repo_add_debpackages(Repo *repo, FILE *fp, int flags)
|
||||
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))
|
||||
|
||||
@@ -306,13 +306,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -327,8 +320,9 @@ 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 */
|
||||
|
||||
@@ -674,14 +674,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
@@ -706,14 +698,14 @@ repo_add_helix(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);
|
||||
|
||||
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);
|
||||
|
||||
@@ -230,7 +230,7 @@ repo_add_mdk(Repo *repo, FILE *fp, int flags)
|
||||
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))
|
||||
@@ -437,14 +437,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -463,9 +455,10 @@ 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))
|
||||
|
||||
@@ -291,19 +291,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -318,7 +305,7 @@ 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);
|
||||
@@ -358,7 +345,11 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags)
|
||||
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);
|
||||
|
||||
@@ -329,13 +329,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -350,9 +343,9 @@ 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))
|
||||
|
||||
@@ -1661,9 +1661,8 @@ repo_add_rpmdb(Repo *repo, Repo *ref, int flags)
|
||||
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)
|
||||
@@ -2044,7 +2043,7 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
|
||||
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;
|
||||
@@ -2096,7 +2095,7 @@ repo_add_rpm_handle(Repo *repo, void *rpmhandle, int flags)
|
||||
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))
|
||||
|
||||
@@ -1091,13 +1091,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
|
||||
@@ -1135,8 +1128,9 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
|
||||
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);
|
||||
|
||||
@@ -427,13 +427,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -447,8 +440,9 @@ 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);
|
||||
|
||||
|
||||
@@ -138,18 +138,6 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -172,7 +160,7 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, 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);
|
||||
|
||||
if (flags & REPO_USE_ROOTDIR)
|
||||
dirpath = pool_prepend_rootdir(repo->pool, dirpath);
|
||||
@@ -190,7 +178,11 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +132,7 @@ solv_xmlparser_init(struct solv_xmlparser *xmlp,
|
||||
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;
|
||||
@@ -169,7 +168,6 @@ solv_xmlparser_init(struct solv_xmlparser *xmlp,
|
||||
xmlp->userdata = userdata;
|
||||
xmlp->startelement = startelement;
|
||||
xmlp->endelement = endelement;
|
||||
xmlp->errorhandler = errorhandler;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -178,6 +176,16 @@ solv_xmlparser_free(struct solv_xmlparser *xmlp)
|
||||
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
|
||||
@@ -197,7 +205,8 @@ free_parser(struct solv_xmlparser *xmlp)
|
||||
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));
|
||||
@@ -216,7 +225,7 @@ parse_block(struct solv_xmlparser *xmlp, char *buf, int l)
|
||||
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;
|
||||
@@ -227,7 +236,7 @@ parse_block(struct solv_xmlparser *xmlp, char *buf, int l)
|
||||
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;
|
||||
@@ -265,9 +274,7 @@ parse_block(struct solv_xmlparser *xmlp, char *buf, int l)
|
||||
{
|
||||
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;
|
||||
@@ -281,11 +288,11 @@ solv_xmlparser_lineno(struct solv_xmlparser *xmlp)
|
||||
|
||||
#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;
|
||||
@@ -295,16 +302,20 @@ solv_xmlparser_parse(struct solv_xmlparser *xmlp, FILE *fp)
|
||||
|
||||
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 *
|
||||
|
||||
@@ -8,6 +8,9 @@ struct solv_xmlparser_element {
|
||||
|
||||
struct solv_xmlparser {
|
||||
void *userdata;
|
||||
char *errstr;
|
||||
unsigned int line;
|
||||
unsigned int column;
|
||||
|
||||
int state;
|
||||
int docontent;
|
||||
@@ -24,12 +27,14 @@ struct solv_xmlparser {
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -41,11 +46,10 @@ 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user