Imported Upstream version 0.7.2
[platform/upstream/libsolv.git] / ext / repo_content.c
index 2a19223..f361900 100644 (file)
@@ -2,6 +2,8 @@
  * repo_content.c
  *
  * Parses 'content' file into .solv
+ * A 'content' file is the repomd.xml of the susetags format
+ *
  * See http://en.opensuse.org/Standards/YaST2_Repository_Metadata/content for a description
  * of the syntax
  *
@@ -13,8 +15,6 @@
  */
 
 #include <sys/types.h>
-#include <limits.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "pool.h"
 #include "repo.h"
 #include "util.h"
+#include "chksum.h"
 #include "repo_content.h"
 #define DISABLE_SPLIT
+#define DISABLE_JOIN2
 #include "tools_util.h"
 
 /* split off a word, return null terminated pointer to it.
@@ -89,7 +91,7 @@ join(struct parsedata *pd, const char *s1, const char *s2, const char *s3)
   if (l > pd->tmpl)
     {
       pd->tmpl = l + 256;
-      pd->tmp = sat_realloc(pd->tmp, pd->tmpl);
+      pd->tmp = solv_realloc(pd->tmp, pd->tmpl);
     }
   p = pd->tmp;
   if (s1)
@@ -129,7 +131,7 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id ma
          dependencies sometimes.  */
       if (!strncmp (name, "package:", 8))
         name += 8;
-      id = str2id(pool, name, 1);
+      id = pool_str2id(pool, name, 1);
       if (*line == '<' || *line == '>' || *line == '=')        /* rel follows */
        {
          char *rel = splitword(&line);
@@ -138,18 +140,18 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id ma
 
          if (!rel || !evr)
            {
-             pool_debug(pool, SAT_FATAL, "repo_content: bad relation '%s %s'\n", name, rel);
-             exit(1);
+             pool_debug(pool, SOLV_ERROR, "repo_content: bad relation '%s %s'\n", name, rel);
+             continue;
            }
          for (flags = 0; flags < 6; flags++)
            if (!strcmp(rel, flagtab[flags]))
              break;
          if (flags == 6)
            {
-             pool_debug(pool, SAT_FATAL, "repo_content: unknown relation '%s'\n", rel);
-             exit(1);
+             pool_debug(pool, SOLV_ERROR, "repo_content: unknown relation '%s'\n", rel);
+             continue;
            }
-         id = rel2id(pool, id, str2id(pool, evr, 1), flags + 1, 1);
+         id = pool_rel2id(pool, id, pool_str2id(pool, evr, 1), flags + 1, 1);
        }
       olddeps = repo_addid_dep(pd->repo, olddeps, id, marker);
     }
@@ -193,7 +195,7 @@ add_multiple_urls(Repodata *data, Id handle, char *value, Id type)
  *
  */
 
-void
+int
 repo_add_content(Repo *repo, FILE *fp, int flags)
 {
   Pool *pool = repo->pool;
@@ -209,6 +211,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
   char *defvendor = 0;
 
   int i = 0;
+  int res = 0;
 
   /* architectures
      we use the first architecture in BASEARCHS or noarch
@@ -220,7 +223,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
   Id *otherarchs = 0;
 
   memset(&pd, 0, sizeof(pd));
-  line = sat_malloc(1024);
+  line = solv_malloc(1024);
   aline = 1024;
 
   pd.repo = repo;
@@ -237,7 +240,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
       if (linep - line + 16 > aline)
        {
          aline = linep - line;
-         line = sat_realloc(line, aline + 512);
+         line = solv_realloc(line, aline + 512);
          linep = line + aline;
          aline += 512;
        }
@@ -269,7 +272,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
          if (istag ("CONTENTSTYLE"))
            {
              if (contentstyle)
-               pool_debug(pool, SAT_ERROR, "repo_content: 'CONTENTSTYLE' must be first line of 'content'\n");
+               pool_debug(pool, SOLV_ERROR, "repo_content: 'CONTENTSTYLE' must be first line of 'content'\n");
              contentstyle = atoi(value);
              continue;
            }
@@ -280,9 +283,32 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
           /* we also replicate some of them into the product solvables
            * to be backward compatible */
 
-         if (istag ("REPOTAGS"))
+         if (istag ("REPOID"))
+           {
+             repodata_add_poolstr_array(data, SOLVID_META, REPOSITORY_REPOID, value);
+             continue;
+           }
+         if (istag ("REPOKEYWORDS"))
            {
-             repodata_add_poolstr_array(data, SOLVID_META, REPOSITORY_GLOBALID, value);
+             add_multiple_strings(data, SOLVID_META, REPOSITORY_KEYWORDS, value);
+             continue;
+           }
+         if (istag ("DISTRO"))
+           {
+             Id dh = repodata_new_handle(data);
+             char *p;
+             /* like with createrepo --distro */
+             if ((p = strchr(value, ',')) != 0)
+               {
+                 *p++ = 0;
+                 if (*value)
+                   repodata_set_poolstr(data, dh, REPOSITORY_PRODUCT_CPEID, value);
+               }
+             else
+               p = value;
+             if (*p)
+               repodata_set_str(data, dh, REPOSITORY_PRODUCT_LABEL, p);
+             repodata_add_flexarray(data, SOLVID_META, REPOSITORY_DISTROS, dh);
              continue;
            }
 
@@ -291,10 +317,10 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
              if (descrdir)
                free(descrdir);
              else
-               repo_set_str(repo, SOLVID_META, SUSETAGS_DESCRDIR, value);
+               repodata_set_str(data, SOLVID_META, SUSETAGS_DESCRDIR, value);
              if (s)
-               repo_set_str(repo, s - pool->solvables, SUSETAGS_DESCRDIR, value);
-             descrdir = strdup(value);
+               repodata_set_str(data, s - pool->solvables, SUSETAGS_DESCRDIR, value);
+             descrdir = solv_strdup(value);
              continue;
            }
          if (istag ("DATADIR"))
@@ -302,10 +328,10 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
              if (datadir)
                free(datadir);
              else
-               repo_set_str(repo, SOLVID_META, SUSETAGS_DATADIR, value);
+               repodata_set_str(data, SOLVID_META, SUSETAGS_DATADIR, value);
              if (s)
-               repo_set_str(repo, s - pool->solvables, SUSETAGS_DATADIR, value);
-             datadir = strdup(value);
+               repodata_set_str(data, s - pool->solvables, SUSETAGS_DATADIR, value);
+             datadir = solv_strdup(value);
              continue;
            }
          if (istag ("VENDOR"))
@@ -313,10 +339,10 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
              if (defvendor)
                free(defvendor);
              else
-               repo_set_poolstr(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR, value);
+               repodata_set_poolstr(data, SOLVID_META, SUSETAGS_DEFAULTVENDOR, value);
              if (s)
-               s->vendor = str2id(pool, value, 1);
-             defvendor = strdup(value);
+               s->vendor = pool_str2id(pool, value, 1);
+             defvendor = solv_strdup(value);
              continue;
            }
 
@@ -332,21 +358,19 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
                continue;
              if (!*value)
                continue;
-             if (!strcasecmp(checksumtype, "sha") || !strcasecmp(checksumtype, "sha1"))
-               l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
-             else if (!strcasecmp(checksumtype, "sha256"))
-               l = SIZEOF_SHA256 * 2, type = REPOKEY_TYPE_SHA256;
-             else if (!strcasecmp(checksumtype, "md5"))
-               l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
-             else
-               {
-                 fprintf(stderr, "Unknown checksum type: %s: %s\n", value, checksumtype);
-                 exit(1);
-               }
-             if (strlen(checksum) != l)
+             type = solv_chksum_str2type(checksumtype);
+             if (!type)
+               {
+                 pool_error(pool, -1, "%s: unknown checksum type '%s'", value, checksumtype);
+                 res = 1;
+                 continue;
+               }
+              l = solv_chksum_len(type);
+             if (strlen(checksum) != 2 * l)
                {
-                 fprintf(stderr, "Invalid checksum length: %s: for %s\n", value, checksum);
-                 exit(1);
+                 pool_error(pool, -1, "%s: invalid checksum length for %s", value, checksumtype);
+                 res = 1;
+                 continue;
                }
              fh = repodata_new_handle(data);
              repodata_set_poolstr(data, fh, SUSETAGS_FILE_TYPE, key);
@@ -365,7 +389,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
                {
                  /* this solvable was created without seeing a
                     PRODUCT entry, just set the name and continue */
-                 s->name = str2id(pool, join(&pd, "product", ":", value), 1);
+                 s->name = pool_str2id(pool, join(&pd, "product", ":", value), 1);
                  continue;
                }
              if (s)
@@ -376,21 +400,20 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
                  if (!s->evr)
                    s->evr = ID_EMPTY;
                  if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
-                   s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
+                   s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
                  if (code10)
-                   s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, 0);
+                   repo_rewrite_suse_deps(s, 0);
                }
              /* create new solvable */
              s = pool_id2solvable(pool, repo_add_solvable(repo));
-             repodata_extend(data, s - pool->solvables);
              handle = s - pool->solvables;
-             s->name = str2id(pool, join(&pd, "product", ":", value), 1);
+             s->name = pool_str2id(pool, join(&pd, "product", ":", value), 1);
              if (datadir)
-               repo_set_str(repo, s - pool->solvables, SUSETAGS_DATADIR, datadir);
+               repodata_set_str(data, s - pool->solvables, SUSETAGS_DATADIR, datadir);
              if (descrdir)
-               repo_set_str(repo, s - pool->solvables, SUSETAGS_DESCRDIR, descrdir);
+               repodata_set_str(data, s - pool->solvables, SUSETAGS_DESCRDIR, descrdir);
              if (defvendor)
-               s->vendor = str2id(pool, defvendor, 1);
+               s->vendor = pool_str2id(pool, defvendor, 1);
              continue;
            }
 
@@ -399,86 +422,81 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
          if (!s)
            {
              s = pool_id2solvable(pool, repo_add_solvable(repo));
-             repodata_extend(data, s - pool->solvables);
              handle = s - pool->solvables;
            }
 
          if (istag ("VERSION"))
-            pd.tmpvers = strdup(value);
+            pd.tmpvers = solv_strdup(value);
           else if (istag ("RELEASE"))
-            pd.tmprel = strdup(value);
+            pd.tmprel = solv_strdup(value);
          else if (code11 && istag ("DISTRIBUTION"))
-           repo_set_str(repo, s - pool->solvables, SOLVABLE_DISTRIBUTION, value);
+           repodata_set_poolstr(data, s - pool->solvables, SOLVABLE_DISTRIBUTION, value);
          else if (istag ("UPDATEURLS"))
-           add_multiple_urls(data, handle, value, str2id(pool, "update", 1));
+           add_multiple_urls(data, handle, value, pool_str2id(pool, "update", 1));
          else if (istag ("EXTRAURLS"))
-           add_multiple_urls(data, handle, value, str2id(pool, "extra", 1));
+           add_multiple_urls(data, handle, value, pool_str2id(pool, "extra", 1));
          else if (istag ("OPTIONALURLS"))
-           add_multiple_urls(data, handle, value, str2id(pool, "optional", 1));
+           add_multiple_urls(data, handle, value, pool_str2id(pool, "optional", 1));
          else if (istag ("RELNOTESURL"))
-           add_multiple_urls(data, handle, value, str2id(pool, "releasenotes", 1));
+           add_multiple_urls(data, handle, value, pool_str2id(pool, "releasenotes", 1));
          else if (istag ("SHORTLABEL"))
-           repo_set_str(repo, s - pool->solvables, PRODUCT_SHORTLABEL, value);
+           repodata_set_str(data, s - pool->solvables, PRODUCT_SHORTLABEL, value);
          else if (istag ("LABEL")) /* LABEL is the products SUMMARY. */
-           repo_set_str(repo, s - pool->solvables, SOLVABLE_SUMMARY, value);
+           repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, value);
          else if (!strncmp (key, "LABEL.", 6))
-           repo_set_str(repo, s - pool->solvables, pool_id2langid(pool, SOLVABLE_SUMMARY, key + 6, 1), value);
+           repodata_set_str(data, s - pool->solvables, pool_id2langid(pool, SOLVABLE_SUMMARY, key + 6, 1), value);
          else if (istag ("FLAGS"))
            add_multiple_strings(data, handle, PRODUCT_FLAGS, value);
          else if (istag ("VENDOR"))    /* actually already handled above */
-           s->vendor = str2id(pool, value, 1);
+           s->vendor = pool_str2id(pool, value, 1);
           else if (istag ("BASEARCHS"))
             {
               char *arch;
 
              if ((arch = splitword(&value)) != 0)
                {
-                 s->arch = str2id(pool, arch, 1);
+                 s->arch = pool_str2id(pool, arch, 1);
                  while ((arch = splitword(&value)) != 0)
                    {
-                      otherarchs = sat_extend(otherarchs, numotherarchs, 1, sizeof(Id), 7);
-                      otherarchs[numotherarchs++] = str2id(pool, arch, 1);
+                      otherarchs = solv_extend(otherarchs, numotherarchs, 1, sizeof(Id), 7);
+                      otherarchs[numotherarchs++] = pool_str2id(pool, arch, 1);
                    }
                }
             }
+         if (!code10)
+           continue;
 
          /*
           * Every tag below is Code10 only
           *
           */
 
-         if (code10 && istag ("DISTPRODUCT"))
-           /* DISTPRODUCT is for registration and Yast, not for the solver. */
-           repo_set_str(repo, s - pool->solvables, PRODUCT_DISTPRODUCT, value);
-         else if (code10 && istag ("DISTVERSION"))
-           /* DISTVERSION is for registration and Yast, not for the solver. */
-           repo_set_str(repo, s - pool->solvables, PRODUCT_DISTVERSION, value);
-         else if (code10 && istag ("ARCH"))
+         if (istag ("ARCH"))
            /* Theoretically we want to have the best arch of the given
               modifiers which still is compatible with the system
               arch.  We don't know the latter here, though.  */
            s->arch = ARCH_NOARCH;
-         else if (code10 && istag ("PREREQUIRES"))
+         else if (istag ("PREREQUIRES"))
            s->requires = adddep(pool, &pd, s->requires, value, SOLVABLE_PREREQMARKER);
-         else if (code10 && istag ("REQUIRES"))
+         else if (istag ("REQUIRES"))
            s->requires = adddep(pool, &pd, s->requires, value, -SOLVABLE_PREREQMARKER);
-         else if (code10 && istag ("PROVIDES"))
+         else if (istag ("PROVIDES"))
            s->provides = adddep(pool, &pd, s->provides, value, 0);
-         else if (code10 && istag ("CONFLICTS"))
+         else if (istag ("CONFLICTS"))
            s->conflicts = adddep(pool, &pd, s->conflicts, value, 0);
-         else if (code10 && istag ("OBSOLETES"))
+         else if (istag ("OBSOLETES"))
            s->obsoletes = adddep(pool, &pd, s->obsoletes, value, 0);
-         else if (code10 && istag ("RECOMMENDS"))
+         else if (istag ("RECOMMENDS"))
            s->recommends = adddep(pool, &pd, s->recommends, value, 0);
-         else if (code10 && istag ("SUGGESTS"))
+         else if (istag ("SUGGESTS"))
            s->suggests = adddep(pool, &pd, s->suggests, value, 0);
-         else if (code10 && istag ("SUPPLEMENTS"))
+         else if (istag ("SUPPLEMENTS"))
            s->supplements = adddep(pool, &pd, s->supplements, value, 0);
-         else if (code10 && istag ("ENHANCES"))
+         else if (istag ("ENHANCES"))
            s->enhances = adddep(pool, &pd, s->enhances, value, 0);
          /* FRESHENS doesn't seem to exist.  */
-         else if (code10 && istag ("TYPE"))
-           repo_set_str(repo, s - pool->solvables, PRODUCT_TYPE, value);
+         else if (istag ("TYPE"))
+           repodata_set_str(data, s - pool->solvables, PRODUCT_TYPE, value);
 
          /* XXX do something about LINGUAS and ARCH?
           * <ma>: Don't think so. zypp does not use or propagate them.
@@ -486,7 +504,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
 #undef istag
        }
       else
-       pool_debug(pool, SAT_ERROR, "repo_content: malformed line: %s\n", line);
+       pool_debug(pool, SOLV_ERROR, "repo_content: malformed line: %s\n", line);
     }
 
   if (datadir)
@@ -496,35 +514,33 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
   if (defvendor)
     free(defvendor);
 
+  if (s && !s->name)
+    {
+      pool_debug(pool, SOLV_ERROR, "repo_content: 'content' incomplete, no product solvable created!\n");
+      s = solvable_free(s, 1);
+    }
   if (s)
     {
-      if (!s->name)
-       {
-         pool_debug(pool, SAT_FATAL, "repo_content: 'content' incomplete, no product solvable created!\n");
-         exit(1);
-       }
-
       if (pd.tmprel)
        s->evr = makeevr(pool, join(&pd, pd.tmpvers, "-", pd.tmprel));
       else
        s->evr = makeevr(pool, pd.tmpvers);
-      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->evr)
        s->evr = ID_EMPTY;
       if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
-        s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
+        s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
       if (code10)
-       s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, 0);
+       repo_rewrite_suse_deps(s, 0);
 
       /* now for every other arch, clone the product except the architecture */
       for (i = 0; i < numotherarchs; ++i)
        {
          Solvable *p = pool_id2solvable(pool, repo_add_solvable(repo));
-         repodata_extend(data, p - pool->solvables);
          p->name = s->name;
          p->evr = s->evr;
          p->vendor = s->vendor;
@@ -532,7 +548,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
 
          /* self provides */
          if (s->name && p->arch != ARCH_SRC && p->arch != ARCH_NOSRC)
-             p->provides = repo_addid_dep(repo, p->provides, rel2id(pool, p->name, p->evr, REL_EQ, 1), 0);
+             p->provides = repo_addid_dep(repo, p->provides, pool_rel2id(pool, p->name, p->evr, REL_EQ, 1), 0);
 
          /* now merge the attributes */
          repodata_merge_attrs(data, p - pool->solvables, s - pool->solvables);
@@ -540,10 +556,10 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
     }
 
   if (pd.tmp)
-    sat_free(pd.tmp);
-  sat_free(line);
-  sat_free(otherarchs);
-  join_freemem();
+    solv_free(pd.tmp);
+  solv_free(line);
+  solv_free(otherarchs);
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
+  return res;
 }