]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Get rid of the xmlparser's error callback
authorMichael Schroeder <mls@suse.de>
Thu, 22 Nov 2018 11:53:20 +0000 (12:53 +0100)
committerMichael Schroeder <mls@suse.de>
Thu, 22 Nov 2018 11:53:20 +0000 (12:53 +0100)
It's much simpler to just return an error from the parse
call.

17 files changed:
ext/repo_appdata.c
ext/repo_arch.c
ext/repo_comps.c
ext/repo_content.c
ext/repo_cudf.c
ext/repo_deb.c
ext/repo_deltainfoxml.c
ext/repo_helix.c
ext/repo_mdk.c
ext/repo_products.c
ext/repo_repomdxml.c
ext/repo_rpmdb.c
ext/repo_rpmmd.c
ext/repo_updateinfoxml.c
ext/repo_zyppdb.c
ext/solv_xmlparser.c
ext/solv_xmlparser.h

index 03098e2359a96f9a44c84613163799733146a87f..3174968693f901d38a2d16cc1b9064bccfe61321 100644 (file)
@@ -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);
index a0c45ce4785b962fd7e4b21acc42bdbfce279f3f..698d5063c768d0e1b876f0c9df7e7a633f9f9ee5 100644 (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)
index 255ecb16cf3f19a76e70256b5e479f85f8a9c718..9400e1eab7815e8a4cf73a88022c3ae02382b94b 100644 (file)
@@ -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);
 
index 68af2d5f967b07b3ccf34bba8e915c75235ff611..f361900e4b52a1d12d9bbe989e530f4a49edc1aa 100644 (file)
@@ -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)
     {
index 14ddcc943a4296664a0fa4f33b311f64e53fea39..64bb86f8b3fd4d8b23cf512d02d7ced9fb6246e0 100644 (file)
@@ -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);
index 6af7f105bf3e7355572f079841eb9d28087a648f..5dd79f4f611d436969aa11a696ded43c5bb90b19 100644 (file)
@@ -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))
index 4eb340f4573d189fc92b10552fda256cc343db2e..ad315da1197dfc550e95dc11c5dd8c795ead3b0c 100644 (file)
@@ -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 */
index 3c2c6d1dfd13f14526643e461abb282c1afbdb1d..37359bbff9f989047178ac76d4f8ee6a99a1ce2f 100644 (file)
@@ -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);
index 418bc61d4f323a78435882b9ee1c8ab2d2f653d1..4d3e102b7a5f3bd9c78208c878a06344cc44a5bf 100644 (file)
@@ -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))
index 154a909f64cad59f9a31caff965a169a26441473..edf15bf7cc3eceb0fe766ba6bea9ede4a53349b4 100644 (file)
@@ -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);
index 760d481f9fe08bb325483a2f51023007e97d42ac..fd46272b1f5dc23833b465bdc233894aa6d93664 100644 (file)
@@ -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))
index a2d518f03ad0b2b6d4c2998ee227a3ddba1bc1e2..9acb400614ac0a6bc63dac3a53788ac5ad685462 100644 (file)
@@ -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))
index 9f49bd31572f7fb61c167d5befa2879bb0e6c924..9bb50a05a484e451050be023a01c1d2b5cb1d25e 100644 (file)
@@ -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);
index 7ba006251545293676f340fc4876021cf634deed..b7c91043242ba6f46d4323525129472ec369de95 100644 (file)
@@ -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);
 
index d73a900236dfc766b9ab40e66ffa0e0a3d1a657e..f6e2bfa64ff0cf47d0d00797566af8cc1cc24857 100644 (file)
@@ -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);
        }
     }
index 170520ff3901c4abf0c380875addd964d722eb8a..a23f4750df61903488c139cf01b8b1b2ac25c0bc 100644 (file)
@@ -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 *
index 9fb342f42b687ea809f116efa2a2be5ee96ad4f5..ced0571f7d610722ad308d2adeb7ac46529082a8 100644 (file)
@@ -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);