fix compile on 64bit
[platform/upstream/libsolv.git] / tools / repo_rpmmd.c
index 5de1714..44ab8ee 100644 (file)
@@ -49,9 +49,10 @@ enum state {
   STATE_DOWNLOADSIZE,
   STATE_INSTALLTIME,
   STATE_INSTALLONLY,
-  
+
   /* Novell/SUSE extended attributes */
   STATE_EULA,
+  STATE_KEYWORD,
   STATE_DISKUSAGE,
   STATE_DIRS,
   STATE_DIR,
@@ -80,8 +81,6 @@ enum state {
   STATE_UPDATEURL,
   STATE_OPTIONALURL,
   STATE_FLAG,
-  STATE_FLAVOR,
-  STATE_REFERENCES,
 
   /* rpm-md dependencies inside the
      format tag */
@@ -134,7 +133,7 @@ static struct stateswitch stateswitches[] = {
   { STATE_START,       "pattern",         STATE_SOLVABLE, 0 },
   { STATE_START,       "patch",           STATE_SOLVABLE, 0 },
   { STATE_START,       "package",         STATE_SOLVABLE, 0 },
-  
+
   { STATE_SOLVABLE,    "name",            STATE_NAME, 1 },
   { STATE_SOLVABLE,    "arch",            STATE_ARCH, 1 },
   { STATE_SOLVABLE,    "version",         STATE_VERSION, 0 },
@@ -142,7 +141,7 @@ static struct stateswitch stateswitches[] = {
   // package attributes rpm-md
   { STATE_SOLVABLE,    "location",        STATE_LOCATION, 0 },
   { STATE_SOLVABLE,    "checksum",        STATE_CHECKSUM, 1 },
-  
+
   /* resobject attributes */
 
   { STATE_SOLVABLE,    "summary",         STATE_SUMMARY,      1 },
@@ -159,8 +158,9 @@ static struct stateswitch stateswitches[] = {
   { STATE_SOLVABLE,    "install-only",    STATE_INSTALLONLY,  1 },
   { STATE_SOLVABLE,    "time",            STATE_TIME,         0 },
 
-  /* extended Novell/SUSE attributes (suseinfo.xml) */
+  /* extended Novell/SUSE attributes (susedata.xml) */
   { STATE_SOLVABLE,    "eula",            STATE_EULA,         1 },
+  { STATE_SOLVABLE,    "keyword",         STATE_KEYWORD,      1 },
   { STATE_SOLVABLE,    "diskusage",       STATE_DISKUSAGE,    0 },
 
   // pattern attribute
@@ -177,14 +177,12 @@ static struct stateswitch stateswitches[] = {
   { STATE_SOLVABLE,    "update-url",        STATE_UPDATEURL,   1 },
   { STATE_SOLVABLE,    "optional-url",      STATE_OPTIONALURL, 1 },
   { STATE_SOLVABLE,    "flag",              STATE_FLAG,        1 },
-  { STATE_SOLVABLE,    "flavor",            STATE_FLAVOR,      1 },
-  { STATE_SOLVABLE,    "references",        STATE_REFERENCES,  1 },
 
   { STATE_SOLVABLE,      "rpm:vendor",      STATE_VENDOR,      1 },
   { STATE_SOLVABLE,      "rpm:group",       STATE_RPM_GROUP,   1 },
   { STATE_SOLVABLE,      "rpm:license",     STATE_RPM_LICENSE, 1 },
 
-  /* rpm-md dependencies */ 
+  /* rpm-md dependencies */
   { STATE_SOLVABLE,      "rpm:provides",    STATE_PROVIDES,     0 },
   { STATE_SOLVABLE,      "rpm:requires",    STATE_REQUIRES,     0 },
   { STATE_SOLVABLE,      "rpm:obsoletes",   STATE_OBSOLETES,    0 },
@@ -197,8 +195,8 @@ static struct stateswitch stateswitches[] = {
   { STATE_SOLVABLE,      "rpm:sourcerpm",   STATE_SOURCERPM,    1 },
   { STATE_SOLVABLE,      "rpm:header-range", STATE_HEADERRANGE, 0 },
   { STATE_SOLVABLE,      "file",            STATE_FILE, 1 },
-  
-   /* extended Novell/SUSE dskusage attributes (suseinfo.xml) */
+
+   /* extended Novell/SUSE diskusage attributes (susedata.xml) */
   { STATE_DISKUSAGE,   "dirs",            STATE_DIRS,         0 },
   { STATE_DIRS,        "dir",             STATE_DIR,          0 },
 
@@ -211,7 +209,7 @@ static struct stateswitch stateswitches[] = {
   { STATE_SUGGESTS,    "rpm:entry",       STATE_SUGGESTSENTRY, 0 },
   { STATE_ENHANCES,    "rpm:entry",       STATE_ENHANCESENTRY, 0 },
   { STATE_FRESHENS,    "rpm:entry",       STATE_FRESHENSENTRY, 0 },
-  
+
   { NUMSTATES}
 };
 
@@ -341,7 +339,7 @@ commit_diskusage (struct parsedata *pd, unsigned handle)
 /*
  * makeevr_atts
  * parse 'epoch', 'ver' and 'rel', return evr Id
- * 
+ *
  */
 
 static Id
@@ -416,7 +414,7 @@ makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
  * I: txt, name of attribute
  * I: atts, list of key/value attributes
  * O: pointer to value of matching key, or NULL
- * 
+ *
  */
 
 static inline const char *
@@ -448,7 +446,7 @@ static char *flagtab[] = {
 /*
  * adddep
  * parse attributes to reldep Id
- * 
+ *
  */
 
 static unsigned int
@@ -483,8 +481,8 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts
          pd->content = sat_realloc(pd->content, l + 256);
          pd->acontent = l + 256;
        }
-      sprintf(pd->content, "%s:%s", k, n); 
-      name = str2id(pool, pd->content, 1); 
+      sprintf(pd->content, "%s:%s", k, n);
+      name = str2id(pool, pd->content, 1);
     }
   else
     name = str2id(pool, (char *)n, 1);
@@ -520,27 +518,27 @@ set_desciption_author(Repodata *data, Id handle, char *str)
   if (!str || !*str)
     return;
   for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
-    if (!strncmp(aut, "\nAuthors:\n--------\n", 19)) 
+    if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
       break;
   if (aut)
     {
       /* oh my, found SUSE special author section */
-      int l = aut - str; 
-      str[l] = 0; 
+      int l = aut - str;
+      str[l] = 0;
       while (l > 0 && str[l - 1] == '\n')
-       str[--l] = 0; 
+       str[--l] = 0;
       if (l)
        repodata_set_str(data, handle, SOLVABLE_DESCRIPTION, str);
       p = aut + 19;
       aut = str;        /* copy over */
       while (*p == ' ' || *p == '\n')
        p++;
-      while (*p) 
+      while (*p)
        {
          if (*p == '\n')
            {
              *aut++ = *p++;
-             while (*p == ' ') 
+             while (*p == ' ')
                p++;
              continue;
            }
@@ -548,7 +546,7 @@ set_desciption_author(Repodata *data, Id handle, char *str)
        }
       while (aut != str && aut[-1] == '\n')
        aut--;
-      *aut = 0; 
+      *aut = 0;
       if (*str)
        repodata_set_str(data, handle, SOLVABLE_AUTHORS, str);
     }
@@ -559,7 +557,7 @@ set_desciption_author(Repodata *data, Id handle, char *str)
 
 /*
  * set_sourcerpm
- * 
+ *
  */
 
 static void
@@ -613,7 +611,7 @@ set_sourcerpm(Repodata *data, Solvable *s, Id handle, char *sourcerpm)
 /*
  * startElement
  * XML callback
- * 
+ *
  */
 
 static void XMLCALL
@@ -643,6 +641,8 @@ startElement(void *userData, const char *name, const char **atts)
     return;
 
   pd->depth++;
+  if (!pd->swtab[pd->state])
+    return;
   for (sw = pd->swtab[pd->state]; sw->from == pd->state; sw++)
     if (!strcmp(sw->ename, name))
       break;
@@ -668,7 +668,7 @@ startElement(void *userData, const char *name, const char **atts)
         pd->kind = "product";
       else if (name[2] == 't' && name[3] == 'c')
         pd->kind = "patch";
-      
+
       /* to support extension metadata files like others.xml which
          have the following structure:
 
@@ -702,9 +702,8 @@ startElement(void *userData, const char *name, const char **atts)
           /* this is a new package */
           pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->common.repo));
           pd->freshens = 0;
-          repodata_extend(pd->data, pd->solvable - pool->solvables);
         }
-      pd->handle = repodata_get_handle(pd->data, (pd->solvable - pool->solvables) - pd->data->start);
+      pd->handle = pd->solvable - pool->solvables;
 #if 0
       fprintf(stderr, "package #%d\n", pd->solvable - pool->solvables);
 #endif
@@ -774,19 +773,7 @@ startElement(void *userData, const char *name, const char **atts)
     case STATE_LOCATION:
       str = find_attr("href", atts);
       if (str)
-       {
-         const char *str2 = strrchr(str, '/');
-         if (str2)
-           {
-             char *str3 = strdup(str);
-             str3[str2 - str] = 0;
-             repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIADIR, str3);
-             free(str3);
-              repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, str2 + 1);
-           }
-         else
-            repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, str);
-       }
+       repodata_set_location(pd->data, handle, 0, 0, str);
       break;
     case STATE_CHECKSUM:
       pd->tmpattr = find_attr("type", atts);
@@ -837,7 +824,7 @@ startElement(void *userData, const char *name, const char **atts)
         /* Really, do nothing, wat for <dir> tag */
         break;
       }
-    case STATE_DIR:  
+    case STATE_DIR:
       {
         long filesz = 0, filenum = 0;
         unsigned dirid;
@@ -846,7 +833,7 @@ startElement(void *userData, const char *name, const char **atts)
             dirid = repodata_str2dir(pd->data, str, 1);
           }
         else
-          {          
+          {
             fprintf( stderr, "<dir .../> tag without 'name' attribute, atts = %p, *atts = %p\n", atts, *atts);
             break;
           }
@@ -874,7 +861,7 @@ startElement(void *userData, const char *name, const char **atts)
 /*
  * endElement
  * XML callback
- * 
+ *
  */
 
 static void XMLCALL
@@ -915,7 +902,8 @@ endElement(void *userData, const char *name)
         s->evr = ID_EMPTY;     /* some patterns have this */
       if (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->supplements = repo_fix_legacy(repo, s->provides, s->supplements, pd->freshens);
+      s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, pd->freshens);
+      s->conflicts = repo_fix_conflicts(repo, s->conflicts);
       pd->freshens = 0;
       pd->kind = 0;
       break;
@@ -965,7 +953,7 @@ endElement(void *userData, const char *name)
             pd->ncscache = index + 1;
           }
         /* add the checksum to the cache */
-        pd->cscache[index-1] = s - pool->solvables;
+        pd->cscache[index] = s - pool->solvables;
         break;
       }
     case STATE_FILE:
@@ -1011,36 +999,41 @@ endElement(void *userData, const char *name)
       break;
     case STATE_RELNOTESURL:
       if (pd->content[0])
-          repodata_set_poolstr(pd->data, handle, PRODUCT_RELNOTESURL, pd->content);
+        {
+          repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
+          repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "releasenotes", 1));
+        }
       break;
     case STATE_UPDATEURL:
       if (pd->content[0])
-          repodata_set_poolstr(pd->data, handle, PRODUCT_EXTRAURLS, pd->content);
+        {
+          repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
+          repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "update", 1));
+        }
       break;
     case STATE_OPTIONALURL:
       if (pd->content[0])
-          repodata_set_poolstr(pd->data, handle, PRODUCT_OPTIONALURLS, pd->content);
+        {
+          repodata_add_poolstr_array(pd->data, pd->handle, PRODUCT_URL, pd->content);
+          repodata_add_idarray(pd->data, pd->handle, PRODUCT_URL_TYPE, str2id(pool, "optional", 1));
+        }
       break;
     case STATE_FLAG:
       if (pd->content[0])
           repodata_set_poolstr(pd->data, handle, PRODUCT_FLAGS, pd->content);
       break;
-    case STATE_FLAVOR:
-      if (pd->content[0])
-        repodata_set_str(pd->data, handle, PRODUCT_FLAVOR, pd->content);
-      break;
-    case STATE_REFERENCES:
-      if (pd->content[0])
-        repodata_set_str(pd->data, handle, PRODUCT_REFERENCES, pd->content);
-      break;
     case STATE_EULA:
       if (pd->content[0])
         repodata_set_str(pd->data, handle, langtag(pd, SOLVABLE_EULA, pd->language), pd->content);
       break;
+    case STATE_KEYWORD:
+      if (pd->content[0])
+        repodata_add_poolstr_array(pd->data, pd->handle, SOLVABLE_KEYWORDS, pd->content);
+      break;
     case STATE_DISKUSAGE:
       if (pd->ndirs)
         commit_diskusage (pd, pd->handle);
-      break;    
+      break;
     default:
       break;
     }
@@ -1053,7 +1046,7 @@ endElement(void *userData, const char *name)
 /*
  * characterData
  * XML callback
- * 
+ *
  */
 
 static void XMLCALL
@@ -1087,7 +1080,7 @@ characterData(void *userData, const XML_Char *s, int len)
 /*
  * repo_add_rpmmd
  * parse rpm-md metadata (primary, others)
- * 
+ *
  */
 
 void
@@ -1098,6 +1091,14 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
   char buf[BUFF_SIZE];
   int i, l;
   struct stateswitch *sw;
+  Repodata *data;
+  unsigned int now;
+
+  now = sat_timems(0);
+  if (!(flags & REPO_REUSE_REPODATA))
+    data = repo_add_repodata(repo, 0);
+  else
+    data = repo_last_repodata(repo);
 
   memset(&pd, 0, sizeof(pd));
   for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++)
@@ -1109,7 +1110,7 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
   pd.common.pool = pool;
   pd.common.repo = repo;
 
-  pd.data = repo_add_repodata(repo, 0);
+  pd.data = data;
 
   pd.content = sat_malloc(256);
   pd.acontent = 256;
@@ -1141,11 +1142,13 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
        break;
     }
   XML_ParserFree(parser);
-
-  if (pd.data)
-    repodata_internalize(pd.data);
   sat_free(pd.content);
   join_freemem();
   stringpool_free(&pd.cspool);
   sat_free(pd.cscache);
+  if (!(flags & REPO_NO_INTERNALIZE))
+    repodata_internalize(data);
+  POOL_DEBUG(SAT_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", sat_timems(now));
+  POOL_DEBUG(SAT_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
+  POOL_DEBUG(SAT_DEBUG_STATS, "repo memory used: %ld K incore, %ld K idarray\n", (unsigned long)data->incoredatalen/1024, (unsigned long)repo->idarraysize / (1024/sizeof(Id)));
 }