Parses updateinfo.xml now and creates .solv file like this:
authorKlaus Kaempf <kkaempf@suse.de>
Fri, 4 Apr 2008 14:01:37 +0000 (14:01 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Fri, 4 Apr 2008 14:01:37 +0000 (14:01 +0000)
  solvable 124:
  name: patch:FEDORA-2008-2070 1.4 <NULL>
  vendor: rel-eng@fedoraproject.org
  conflicts:
    dbus-debuginfo < 1.1.2-9.fc8
    dbus-x11 < 1.1.2-9.fc8
    dbus-devel < 1.1.2-9.fc8
    dbus-libs < 1.1.2-9.fc8
    dbus < 1.1.2-9.fc8
  update:severity: security
  solvable:summary: dbus-1.1.2-9.fc8
  update:timestamp: 2008-02-28 21:10:49
  solvable:description:
  update:reboot: True

tools/repo_updateinfoxml.c

index 5ae82ea..1dd3318 100644 (file)
@@ -6,6 +6,7 @@
  * for further information
  */
 
+#define _GNU_SOURCE
 #include <sys/types.h>
 #include <limits.h>
 #include <fcntl.h>
 #include "repo.h"
 #include "repo_patchxml.h"
 #include "repo_rpmmd.h"
+#include "tools_util.h"
 
 //#define TESTMM
 
 /*
-<updates>
-  <update from="rel-eng@fedoraproject.org" status="stable" type="security" version="1.4">
-    <id>FEDORA-2007-4594</id>
-    <title>imlib-1.9.15-6.fc8</title>
-    <release>Fedora 8</release>
-    <issued date="2007-12-28 16:42:30"/>
-    <references>
-      <reference href="https://bugzilla.redhat.com/show_bug.cgi?id=426091" id="426091" title="CVE-2007-3568 imlib: infinite loop DoS using crafted BMP image" type="bugzilla"/>
-    </references>
-    <description>This update includes a fix for a denial-of-service issue (CVE-2007-3568) whereby an attacker who could get an imlib-using user to view a  specially-crafted BMP image could cause the user's CPU to go into an infinite loop.</description>
-    <pkglist>
-      <collection short="F8">
-        <name>Fedora 8</name>
-        <package arch="ppc64" name="imlib-debuginfo" release="6.fc8" src="http://download.fedoraproject.org/pub/fedora/linux/updates/8/ppc64/imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm" version="1.9.15">
-          <filename>imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm</filename>
-        </package>
+ * <updates>
+ *   <update from="rel-eng@fedoraproject.org" status="stable" type="security" version="1.4">
+ *     <id>FEDORA-2007-4594</id>
+ *     <title>imlib-1.9.15-6.fc8</title>
+ *     <release>Fedora 8</release>
+ *     <issued date="2007-12-28 16:42:30"/>
+ *     <references>
+ *       <reference href="https://bugzilla.redhat.com/show_bug.cgi?id=426091" id="426091" title="CVE-2007-3568 imlib: infinite loop DoS using crafted BMP image" type="bugzilla"/>
+ *     </references>
+ *     <description>This update includes a fix for a denial-of-service issue (CVE-2007-3568) whereby an attacker who could get an imlib-using user to view a  specially-crafted BMP image could cause the user's CPU to go into an infinite loop.</description>
+ *     <pkglist>
+ *       <collection short="F8">
+ *         <name>Fedora 8</name>
+ *         <package arch="ppc64" name="imlib-debuginfo" release="6.fc8" src="http://download.fedoraproject.org/pub/fedora/linux/updates/8/ppc64/imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm" version="1.9.15">
+ *           <filename>imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm</filename>
+ *           <reboot_suggested>True</reboot_suggested>
+ *         </package>
+ *       </collection>
+ *     </pkglist>
+ *   </update>
+ * </updates>
 */
 
 enum state {
@@ -56,6 +63,7 @@ enum state {
   STATE_NAME,        /* 12 */
   STATE_PACKAGE,     /* 13 */
   STATE_FILENAME,    /* 14 */
+  STATE_REBOOT,      /* 15 */
   NUMSTATES
 };
 
@@ -84,6 +92,7 @@ static struct stateswitch stateswitches[] = {
   { STATE_COLLECTION,  "name",            STATE_NAME,        1 },
   { STATE_COLLECTION,  "package",         STATE_PACKAGE,     0 },
   { STATE_PACKAGE,     "filename",        STATE_FILENAME,    1 },
+  { STATE_PACKAGE,     "reboot_suggested",STATE_REBOOT,      1 },
   { NUMSTATES }
 };
 
@@ -100,7 +109,6 @@ struct parsedata {
   Repodata *data;
   unsigned int datanum;
   Solvable *solvable;
-  char *kind;
   unsigned int timestamp;
   
   struct stateswitch *swtab[NUMSTATES];
@@ -127,16 +135,88 @@ find_attr(const char *txt, const char **atts)
 }
 */
 
+
+/*
+ * create evr (as Id) from 'epoch', 'version' and 'release' attributes
+ */
+
+static Id
+makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts)
+{
+  const char *e, *v, *r, *v2;
+  char *c;
+  int l;
+
+  e = v = r = 0;
+  for (; *atts; atts += 2)
+    {
+      if (!strcmp(*atts, "epoch"))
+       e = atts[1];
+      else if (!strcmp(*atts, "version"))
+       v = atts[1];
+      else if (!strcmp(*atts, "release"))
+       r = atts[1];
+    }
+  if (e && !strcmp(e, "0"))
+    e = 0;
+  if (v && !e)
+    {
+      for (v2 = v; *v2 >= '0' && *v2 <= '9'; v2++)
+        ;
+      if (v2 > v && *v2 == ':')
+       e = "0";
+    }
+  l = 1;
+  if (e)
+    l += strlen(e) + 1;
+  if (v)
+    l += strlen(v);
+  if (r)
+    l += strlen(r) + 1;
+  if (l > pd->acontent)
+    {
+      pd->content = realloc(pd->content, l + 256);
+      pd->acontent = l + 256;
+    }
+  c = pd->content;
+  if (e)
+    {
+      strcpy(c, e);
+      c += strlen(c);
+      *c++ = ':';
+    }
+  if (v)
+    {
+      strcpy(c, v);
+      c += strlen(c);
+    }
+  if (r)
+    {
+      *c++ = '-';
+      strcpy(c, r);
+      c += strlen(c);
+    }
+  *c = 0;
+  if (!*pd->content)
+    return 0;
+#if 0
+  fprintf(stderr, "evr: %s\n", pd->content);
+#endif
+  return str2id(pool, pd->content, 1);
+}
+
+
+
 static void XMLCALL
 startElement(void *userData, const char *name, const char **atts)
 {
   struct parsedata *pd = userData;
   Pool *pool = pd->pool;
-  /*Solvable *s = pd->solvable;*/
+  Solvable *solvable = pd->solvable;
   struct stateswitch *sw;
   /*const char *str; */
 
-#if 1
+#if 0
       fprintf(stderr, "start: [%d]%s\n", pd->state, name);
 #endif
   if (pd->depth != pd->statedepth)
@@ -154,6 +234,7 @@ startElement(void *userData, const char *name, const char **atts)
     {
 #if 1
       fprintf(stderr, "into unknown: [%d]%s (from: %d)\n", sw->to, name, sw->from);
+      exit( 1 );
 #endif
       return;
     }
@@ -163,47 +244,124 @@ startElement(void *userData, const char *name, const char **atts)
   pd->lcontent = 0;
   *pd->content = 0;
 
-#if 1
-      fprintf(stderr, "state: %d\n", pd->state);
-#endif
   switch(pd->state)
     {
-     case STATE_START:
+      case STATE_START:
       break;
-     case STATE_UPDATES:
+      case STATE_UPDATES:
       break;
-     case STATE_UPDATE:
-      pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
-      pd->datanum = (pd->solvable - pool->solvables) - pd->repo->start;
-      repodata_extend(pd->data, pd->solvable - pool->solvables);      
+      /*
+       * <update from="rel-eng@fedoraproject.org"
+       *         status="stable"
+       *         type="bugfix" (enhancement, security)
+       *         version="1.4">
+       */
+      case STATE_UPDATE:
+      {
+       const char *from, *status, *type, *version;
+       for (; *atts; atts += 2)
+       {
+         if (!strcmp(*atts, "from"))
+           from = atts[1];
+         else if (!strcmp(*atts, "status"))
+           status = atts[1];
+         else if (!strcmp(*atts, "type"))
+           type = atts[1];
+         else if (!strcmp(*atts, "version"))
+           version = atts[1];
+       }
+       
+       solvable = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
+       pd->datanum = (pd->solvable - pool->solvables) - pd->repo->start;
+       repodata_extend(pd->data, pd->solvable - pool->solvables);      
+       
+       solvable->vendor = str2id(pool, (char *)from, 1);
+       solvable->evr = str2id(pool, (char *)version, 1);
+       repodata_set_str(pd->data, pd->datanum, UPDATE_SEVERITY, type);
+      }
       break;
-     case STATE_ID:
+      /* <id>FEDORA-2007-4594</id> */
+      case STATE_ID:
       break;
-     case STATE_TITLE:
+      /* <title>imlib-1.9.15-6.fc8</title> */
+      case STATE_TITLE:
       break;
-     case STATE_RELEASE:
+      /* <release>Fedora 8</release> */
+      case STATE_RELEASE:
       break;
-     case STATE_ISSUED:
+      /*  <issued date="2008-03-21 21:36:55"/>
+      */
+      case STATE_ISSUED:
+      {
+       const char *date;
+       for (; *atts; atts += 2)
+       {
+         if (!strcmp(*atts, "date"))
+           date = atts[1];
+       }
+       repodata_set_str(pd->data, pd->datanum, UPDATE_TIMESTAMP, date);
+      }
       break;
-     case STATE_REFERENCES:
+      case STATE_REFERENCES:
       break;
-     case STATE_REFERENCE:
+      /*  <reference href="https://bugzilla.redhat.com/show_bug.cgi?id=330471"
+       *             id="330471"
+       *             title="LDAP schema file missing for dhcpd"
+       *             type="bugzilla"/>
+       */
+      case STATE_REFERENCE:
       break;
-     case STATE_DESCRIPTION:
+      /* <description>This update ...</description> */
+      case STATE_DESCRIPTION:
       break;
-     case STATE_PKGLIST:
+      case STATE_PKGLIST:
       break;
-     case STATE_COLLECTION:
+      /* <collection short="F8"> */
+      case STATE_COLLECTION:
       break;
-     case STATE_NAME:
+      /* <name>Fedora 8</name> */ 
+      case STATE_NAME:
       break;
-     case STATE_PACKAGE:
+      /*   <package arch="ppc64" name="imlib-debuginfo" release="6.fc8"
+       *            src="http://download.fedoraproject.org/pub/fedora/linux/updates/8/ppc64/imlib-debuginfo-1.9.15-6.fc8.ppc64.rpm"
+       *            version="1.9.15">
+       * 
+       * -> patch.conflicts: {name} < {version}.{release}
+       */
+      case STATE_PACKAGE:
+      {
+       const char *arch, *name, *src;
+       Id evr = makeevr_atts(pool, pd, atts); /* parse "epoch", "version", "release" */
+       Id n;
+       Id rel_id;
+       for (; *atts; atts += 2)
+       {
+         if (!strcmp(*atts, "arch"))
+           arch = atts[1];
+         else if (!strcmp(*atts, "name"))
+           name = atts[1];
+         else if (!strcmp(*atts, "src"))
+           src = atts[1];
+       }
+       n = str2id(pool, name, 1);
+       rel_id = rel2id(pool, n, evr, REL_LT, 1);
+
+       solvable->conflicts = repo_addid_dep(pd->repo, solvable->conflicts, rel_id, 0);
+      }
       break;
-     case STATE_FILENAME:
+      /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */ 
+      case STATE_FILENAME:
       break;
-     default:
+      /* <reboot_suggested>True</reboot_suggested> */
+      case STATE_REBOOT:
+      break;
+      case NUMSTATES+1:
+        split(NULL, NULL, 0); /* just to keep gcc happy about tools_util.h: static ... split() {...}  Urgs!*/
+      break;
+      default:
       break;
     }
+  return;
 }
 
 
@@ -214,7 +372,7 @@ endElement(void *userData, const char *name)
   Pool *pool = pd->pool;
   Solvable *s = pd->solvable;
 
-#if 1
+#if 0
       fprintf(stderr, "end: %s\n", name);
 #endif
   if (pd->depth != pd->statedepth)
@@ -239,41 +397,66 @@ endElement(void *userData, const char *name)
       case STATE_ID:
       {
         if (pd->content) {
-         s->name = str2id(pool, pd->content, 1);
+         s->name = str2id(pool, join2("patch", ":", pd->content), 1);
        }
       }
       break;
+      /* <title>imlib-1.9.15-6.fc8</title> */
       case STATE_TITLE:
       {
+       while (pd->lcontent > 0
+              && *(pd->content + pd->lcontent - 1) == '\n')
+       {
+         --pd->lcontent;
+         *(pd->content + pd->lcontent) = 0;
+       }
        repodata_set_str(pd->data, pd->datanum, SOLVABLE_SUMMARY, pd->content);
       }
       break;
-        case STATE_RELEASE:
-        case STATE_ISSUED:
-            s->name = str2id(pool, pd->content, 1);
-     case STATE_REFERENCES:
+      /*
+       * <release>Fedora 8</release>
+       */
+      case STATE_RELEASE:
       break;
-        case STATE_REFERENCE:
-        case STATE_DESCRIPTION:
-            repodata_set_str(pd->data, pd->datanum, SOLVABLE_DESCRIPTION, pd->content);
-            break;   
-     case STATE_PKGLIST:
+      case STATE_ISSUED:
       break;
-     case STATE_COLLECTION:
+      case STATE_REFERENCES:
       break;
-     case STATE_NAME:
+      case STATE_REFERENCE:
       break;
-     case STATE_PACKAGE:
+      /*
+       * <description>This update ...</description>
+       */
+      case STATE_DESCRIPTION:
+      {
+       repodata_set_str(pd->data, pd->datanum, SOLVABLE_DESCRIPTION, pd->content);
+      }
+      break;   
+      case STATE_PKGLIST:
       break;
-     case STATE_FILENAME:
+      case STATE_COLLECTION:
+      break;
+      case STATE_NAME:
+      break;
+      case STATE_PACKAGE:
+      break;
+      /* <filename>libntlm-0.4.2-1.fc8.x86_64.rpm</filename> */ 
+      case STATE_FILENAME:
+      break;
+      /* <reboot_suggested>True</reboot_suggested> */
+      case STATE_REBOOT:
+      {
+       repodata_set_str(pd->data, pd->datanum, UPDATE_REBOOT, pd->content);
+      }
+      break;
+      default:
       break;
-
-        default:
-            break;
     }
 
   pd->state = pd->sbtab[pd->state];
   pd->docontent = 0;
+  
+  return;
 }
 
 
@@ -283,11 +466,14 @@ characterData(void *userData, const XML_Char *s, int len)
   struct parsedata *pd = userData;
   int l;
   char *c;
+  if (!pd->docontent) {
 #if 0
-  fprintf(stderr, "Content: [%d]'%s'\n", len, s );
+    char *dup = strndup( s, len );
+  fprintf(stderr, "Content: [%d]'%s'\n", pd->state, dup );
+  free( dup );
 #endif
-  if (!pd->docontent)
     return;
+  }
   l = pd->lcontent + len + 1;
   if (l > pd->acontent)
     {