- cleanup repo handlin API
[platform/upstream/libsolv.git] / tools / repo_rpmmd.c
index b9b65f9..c1e33d4 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
 #include <sys/types.h>
 #include <limits.h>
 #include <fcntl.h>
@@ -7,6 +14,7 @@
 #include <expat.h>
 
 #include "pool.h"
+#include "util.h"
 #include "repo_rpmmd.h"
 
 
@@ -18,6 +26,7 @@ enum state {
   STATE_ARCH,
   STATE_VERSION,
   STATE_FORMAT,
+  STATE_VENDOR,
   STATE_PROVIDES,
   STATE_PROVIDESENTRY,
   STATE_REQUIRES,
@@ -55,6 +64,7 @@ static struct stateswitch stateswitches[] = {
   { STATE_PACKAGE,     "arch",            STATE_ARCH, 1 },
   { STATE_PACKAGE,     "version",         STATE_VERSION, 0 },
   { STATE_PACKAGE,     "format",          STATE_FORMAT, 0 },
+  { STATE_FORMAT,      "rpm:vendor",      STATE_VENDOR, 1 },
   { STATE_FORMAT,      "rpm:provides",    STATE_PROVIDES, 0 },
   { STATE_FORMAT,      "rpm:requires",    STATE_REQUIRES, 0 },
   { STATE_FORMAT,      "rpm:obsoletes",   STATE_OBSOLETES , 0 },
@@ -129,7 +139,7 @@ makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
     l += strlen(r) + 1;
   if (l > pd->acontent)
     {
-      pd->content = realloc(pd->content, l + 256);
+      pd->content = xrealloc(pd->content, l + 256);
       pd->acontent = l + 256;
     }
   c = pd->content;
@@ -196,7 +206,7 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts
       int l = strlen(k) + 1 + strlen(n) + 1;
       if (l > pd->acontent)
        {
-         pd->content = realloc(pd->content, l + 256);
+         pd->content = xrealloc(pd->content, l + 256);
          pd->acontent = l + 256;
        }
       sprintf(pd->content, "%s:%s", k, n); 
@@ -263,8 +273,8 @@ startElement(void *userData, const char *name, const char **atts)
 #if 0
              fprintf(stderr, "numpacks: %d\n", pd->numpacks);
 #endif
-             pool->solvables = realloc(pool->solvables, (pool->nsolvables + pd->numpacks) * sizeof(Solvable));
-             pd->start = pool->solvables + pd->repo->start;
+             pool->solvables = xrealloc2(pool->solvables, (pool->nsolvables + pd->numpacks), sizeof(Solvable));
+             pd->start = pool->solvables + pool->nsolvables;
              memset(pd->start, 0, pd->numpacks * sizeof(Solvable));
            }
        }
@@ -374,6 +384,9 @@ endElement(void *userData, const char *name)
     case STATE_ARCH:
       s->arch = str2id(pool, pd->content, 1);
       break;
+    case STATE_VENDOR:
+      s->vendor = str2id(pool, pd->content, 1);
+      break;
     case STATE_FILE:
       id = str2id(pool, pd->content, 1);
       s->provides = repo_addid(pd->repo, s->provides, id);
@@ -398,7 +411,7 @@ characterData(void *userData, const XML_Char *s, int len)
   l = pd->lcontent + len + 1;
   if (l > pd->acontent)
     {
-      pd->content = realloc(pd->content, l + 256);
+      pd->content = xrealloc(pd->content, l + 256);
       pd->acontent = l + 256;
     }
   c = pd->content + pd->lcontent;
@@ -411,16 +424,20 @@ characterData(void *userData, const XML_Char *s, int len)
 
 #define BUFF_SIZE 8192
 
-Repo *
-pool_addrepo_rpmmd(Pool *pool, FILE *fp)
+void
+repo_add_rpmmd(Repo *repo, FILE *fp)
 {
+  Pool *pool = repo->pool;
   struct parsedata pd;
   char buf[BUFF_SIZE];
   int i, l;
-  Repo *repo;
   struct stateswitch *sw;
 
-  repo = pool_addrepo_empty(pool);
+  if (repo->start && repo->start + repo->nsolvables != pool->nsolvables)
+    abort();
+  if (!repo->start)
+    repo->start = pool->nsolvables;
+
   memset(&pd, 0, sizeof(pd));
   for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
     {
@@ -451,8 +468,7 @@ pool_addrepo_rpmmd(Pool *pool, FILE *fp)
   XML_ParserFree(parser);
 
   pool->nsolvables += pd.pack;
-  repo->nsolvables = pd.pack;
+  repo->nsolvables += pd.pack;
 
   free(pd.content);
-  return repo;
 }