- add repo_add_poolstr_array
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 12 Sep 2008 12:02:11 +0000 (12:02 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 12 Sep 2008 12:02:11 +0000 (12:02 +0000)
- move updates="key,key.." to repomd.xml

src/repo.c
src/repo.h
tools/repo_repomdxml.c
tools/repo_updateinfoxml.c

index df9a414..b829fcd 100644 (file)
@@ -1029,6 +1029,17 @@ repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str)
 }
 
 void
+repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str)
+{
+  Repodata *data = repo_findrepodata(repo, p, keyname);
+  if (p < 0)
+    p = p + data->extrastart;
+  else
+    p = p - data->start;
+  repodata_add_poolstr_array(data, repodata_get_handle(data, p), keyname, str);
+}
+
+void
 repo_internalize(Repo *repo)
 {
   int i;
index ee19efb..67d44cf 100644 (file)
@@ -228,6 +228,7 @@ void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
 void repo_set_num(Repo *repo, Id p, Id keyname, Id num);
 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
+void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
 void repo_internalize(Repo *repo);
 void repo_disable_paging(Repo *repo);
 
index f137ce6..f387406 100644 (file)
@@ -92,6 +92,34 @@ static struct stateswitch stateswitches[] = {
   { NUMSTATES }
 };
 
+/*
+ * split l into m parts, store to sp[]
+ *  split at whitespace
+ */
+
+static inline int
+split_comma(char *l, char **sp, int m)
+{
+  int i;
+  for (i = 0; i < m;)
+    {
+      while (*l == ',')
+       l++;
+      if (!*l)
+       break;
+      sp[i++] = l;
+      if (i == m)
+        break;
+      while (*l && !(*l == ','))
+       l++;
+      if (!*l)
+       break;
+      *l++ = 0;
+    }
+  return i;
+}
+
+
 struct parsedata {
   int depth;
   enum state state;
@@ -113,7 +141,7 @@ struct parsedata {
  * find attribute
  */
 
-static const char *
+static inline const char *
 find_attr(const char *txt, const char **atts)
 {
   for (; *atts; atts += 2)
@@ -124,6 +152,7 @@ find_attr(const char *txt, const char **atts)
   return 0;
 }
 
+
 static void XMLCALL
 startElement(void *userData, const char *name, const char **atts)
 {
@@ -165,15 +194,44 @@ startElement(void *userData, const char *name, const char **atts)
     {
     case STATE_START: break;
     case STATE_REPOMD:
-      expirestr = find_attr("expire", atts);
-      if ( expirestr != NULL )
-        expire = atoi(expirestr);
-      if ( expire > 0 )
-        {
-          /* save the timestamp in the non solvable number 1 */
-          repo_set_num(pd->repo, -1, REPOSITORY_EXPIRE, expire);
+      {
+        const char *updstr;
+        char *value;
+        char *fvalue;
+
+        expirestr = (char*) find_attr("expire", atts);
+        if ( expirestr != NULL )
+          expire = atoi(expirestr);
+        if ( expire > 0 )
+          {
+            /* save the timestamp in the non solvable number 1 */
+            repo_set_num(pd->repo, -1, REPOSITORY_EXPIRE, expire);
+          }
+
+        updstr = find_attr("updates", atts);
+        if ( updstr != NULL )
+          {
+            value = strdup(updstr);
+            fvalue = value; /* save the first */
+            if ( value != NULL )
+              {
+                char *sp[2];
+                while (value)
+                  {
+                    int words = split_comma(value, sp, 2);
+                    if (!words)
+                      break;
+                    if (sp[0])
+                      repo_add_poolstr_array(pd->repo, -1, REPOSITORY_UPDATES, sp[0]);
+                    if (words == 1)
+                      break;
+                    value = sp[1];
+                  }
+                free(fvalue);
+              }
+          }
+          break;
         }
-      break;
     case STATE_DATA: break;
     case STATE_LOCATION: break;
     case STATE_CHECKSUM: break;
index 618d6a4..b96b972 100644 (file)
@@ -135,22 +135,6 @@ struct parsedata {
 static int package_filename_seen = 0;
 static int package_flags = 0; /* same for reboot/restart flags, to be written at </package> */
 
-
-/*
- * find attribute
- */
-
-static const char *
-find_attr(const char *txt, const char **atts)
-{
-  for (; *atts; atts += 2)
-    {
-      if (!strcmp(*atts, txt))
-        return atts[1];
-    }
-  return 0;
-}
-
 /*
  * create evr (as Id) from 'epoch', 'version' and 'release' attributes
  */
@@ -360,15 +344,9 @@ startElement(void *userData, const char *name, const char **atts)
       break;
       case STATE_PKGLIST:
       break;
-      /* <collection short="F8" id="PRODUCT0001444"> */
+      /* <collection short="F8" */
       case STATE_COLLECTION:
-        {
-          /* insert a REPOSITORY_UPDATES for every present collection id */
-          const char *cid;
-          if ((cid = find_attr("id", atts)))
-            repodata_add_poolstr_array(pd->data, -1, REPOSITORY_UPDATES, cid);
-          break;
-        }
+      break;
       /* <name>Fedora 8</name> */ 
       case STATE_NAME:
       break;