- add CPE (Common Platform Enumeration) attribute to installed product
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 22 Sep 2008 10:53:39 +0000 (10:53 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 22 Sep 2008 10:53:39 +0000 (10:53 +0000)
- read keywords, products and expire from suseinfo

src/knownid.h
tools/repo2solv.sh
tools/repo_products.c
tools/repo_repomdxml.c

index 0df80fd..ae49987 100644 (file)
@@ -158,6 +158,7 @@ KNOWNID(PRODUCT_REFERENCES,         "product:references"),
 KNOWNID(PRODUCT_UPDATEREPOKEY,         "product:updaterepokey"),
 KNOWNID(PRODUCT_REGISTER_TARGET,       "product:regtarget"),
 KNOWNID(PRODUCT_REGISTER_RELEASE,      "product:regrelease"),
+KNOWNID(PRODUCT_CPE_NAME,              "product:cpename"),
 
 /* argh */
 KNOWNID(SUSETAGS_DATADIR,              "susetags:datadir"),
@@ -169,6 +170,10 @@ KNOWNID(REPOSITORY_TIMESTAMP,           "repository:timestamp"),
 KNOWNID(REPOSITORY_EXPIRE,              "repository:expire"),
 /* which things does this repo provides updates for, if it does */
 KNOWNID(REPOSITORY_UPDATES,              "repository:updates"),
+/* which products this repository is supposed to be for */
+KNOWNID(REPOSITORY_PRODUCTS,             "repository:products"),
+/* keyword (tags) for this repository */
+KNOWNID(REPOSITORY_KEYWORDS,             "repository:keywords"),
 
 KNOWNID(DELTA_PACKAGE_NAME,            "delta:pkgname"),
 KNOWNID(DELTA_PACKAGE_EVR,              "delta:pkgevr"),
index e214589..01a9c1b 100755 (executable)
@@ -30,40 +30,35 @@ cd "$dir" || exit 1
 if test -d repodata; then
   cd repodata || exit 2
 
-  # This contains a primary.xml* and maybe patches
-  for i in primary.xml*; do
-    case $i in
-      *.gz) cmd="gzip -dc" ;;
-      *.bz2) cmd="bzip2 -dc" ;;
-      *) cmd="cat" ;;
-    esac
-    # only check the first primary.xml*, in case there are more
-    break
-  done
   primfile="/nonexist"
-  if test -n "$cmd"; then
-    # we have some primary.xml*
+  if test -f primary.xml || test -f primary.xml.gz || test -f primary.xml.bz2 ; then
     primfile=`mktemp` || exit 3
-    $cmd $i | rpmmd2solv $parser_options > $primfile || exit 4
-  fi
-
-  # This contains a susedata.xml* with extended primary data
- if test -f susedata.xml || test -f susedata.xml.gz || test -f susedata.xml.bz2 ; then
+    (
+     # fake tag to combine primary.xml and extensions
+     # like susedata.xml, other.xml, filelists.xml
+     echo '<rpmmd>'
+     for i in primary.xml* susedata.xml*; do
+       case $i in
+         *.gz) gzip -dc "$i";;
+        *.bz2) bzip2 -dc "$i";;
+        *) cat "$i";;
+       esac
+       # add a newline
+       echo
+       # only the first
+       break
+     done
      for i in susedata.xml*; do
-         case $i in
-             *.gz) cmd="gzip -dc" ;;
-             *.bz2) cmd="bzip2 -dc" ;;
-             *) cmd="cat" ;;
-         esac
-    # only check the first susedata.xml*, in case there are more
-         break
+       case $i in
+         *.gz) gzip -dc "$i";;
+        *.bz2) bzip2 -dc "$i";;
+         *) cat "$i";;
+       esac
+       # only the first
+       break
      done
-     susedatafile="/nonexist"
-     if test -n "$cmd"; then
-    # we have some susedata.xml*
-         susedatafile=`mktemp` || exit 3
-         $cmd $i | rpmmd2solv $parser_options > $susedatafile || exit 4
-     fi
+     echo '</rpmmd>'
+    ) | grep -v '\?xml' |  sed '1i\<?xml version="1.0" encoding="UTF-8"?>' | rpmmd2solv $parser_options > $primfile || exit 4
   fi
 
   prodfile="/nonexist"
@@ -84,7 +79,7 @@ if test -d repodata; then
 
 
   # This contains repomd.xml
-  # for now we only read some keys like expiration
+  # for now we only read some keys like timestamp
   if test -f repomd.xml || test -f repomd.xml.gz || test -f repomd.xml.bz2 ; then
       for i in repomd.xml*; do
           case $i in
@@ -104,6 +99,27 @@ if test -d repodata; then
       fi
   fi
 
+  # This contains suseinfo.xml, which is extensions to repomd.xml
+  # for now we only read some keys like expiration and products
+  if test -f suseinfo.xml || test -f suseinfo.xml.gz || test -f suseinfo.xml.bz2 ; then
+      for i in suseinfo.xml*; do
+          case $i in
+              *.gz) cmd="gzip -dc" ;;
+              *.bz2) cmd="bzip2 -dc" ;;
+              *) cmd="cat" ;;
+          esac
+          # only check the first suseinfo.xml*, in case there are more
+          break
+      done
+
+      suseinfofile="/nonexist"
+      if test -n "$cmd"; then
+      # we have some suseinfo.xml*
+          suseinfofile=`mktemp` || exit 3
+          $cmd $i | repomdxml2solv $parser_options > $suseinfofile || exit 4
+      fi
+  fi
+
   # This contains a updateinfo.xml* and maybe patches
   if test -f updateinfo.xml || test -f updateinfo.xml.gz || test -f updateinfo.xml.bz2 ; then
       for i in updateinfo.xml*; do
@@ -162,8 +178,8 @@ if test -d repodata; then
   if test -s $repomdfile; then
     m_repomdfile=$repomdfile
   fi
-  if test -s $susedatafile; then
-    m_susedata=$susedatafile
+  if test -s $suseinfofile; then
+    m_suseinfofile=$suseinfofile
   fi
   if test -s $primfile; then
     m_primfile=$primfile
@@ -180,8 +196,8 @@ if test -d repodata; then
   if test -s $deltainfofile; then
     m_deltainfofile=$deltainfofile
   fi
-  mergesolv $m_repomdfile $m_primfile $m_susedatafile $m_prodfile $m_patchfile $m_updateinfofile $m_deltainfofile
-  rm -f $repomdfile $primfile $prodfile $patchfile $updateinfofile $deltainfofile
+  mergesolv $m_repomdfile $m_suseinfofile $m_primfile $m_prodfile $m_patchfile $m_updateinfofile $m_deltainfofile
+  rm -f $repomdfile $suseinfofile $primfile $prodfile $patchfile $updateinfofile $deltainfofile
 
 elif test_susetags; then
   olddir=`pwd`
index 3f71fe2..b42d6da 100644 (file)
@@ -43,7 +43,8 @@ enum state {
   STATE_ARCH,            // 6
   STATE_SUMMARY,         // 7
   STATE_DESCRIPTION,     // 8
-  STATE_UPDATEREPOKEY,   // 9
+  STATE_UPDATEREPOKEY,   // 9 should go away
+  STATE_CPENAME,         // 9
   STATE_URLS,            // 10
   STATE_URL,             // 11
   STATE_RUNTIMECONFIG,   // 12
@@ -78,6 +79,7 @@ static struct stateswitch stateswitches[] = {
   { STATE_PRODUCT,   "runtimeconfig", STATE_RUNTIMECONFIG, 0 },
   { STATE_PRODUCT,   "linguas",       STATE_LINGUAS,       0 },
   { STATE_PRODUCT,   "updaterepokey", STATE_UPDATEREPOKEY, 1 },
+  { STATE_PRODUCT,   "cpename",       STATE_CPENAME,       1 },
   { STATE_URLS,      "url",           STATE_URL,           1 },
   { STATE_LINGUAS,   "lang",          STATE_LANG,          0 },
   { STATE_REGISTER,  "flavor",        STATE_FLAVOR,        1 },
@@ -351,6 +353,9 @@ endElement(void *userData, const char *name)
          printf("%s\n", pd->content);
        }
     break;
+    case STATE_CPENAME:
+      if (pd->content)
+        repodata_set_str(pd->data, pd->handle, PRODUCT_CPE_NAME, pd->content);
     default:
       break;
     }
index dce33c2..05935c8 100644 (file)
 <open-checksum type="sha">24f8252f3dd041e37e7c3feb2d57e02b4422d316</open-checksum>
 </data>
 </repomd>
+
+support also extension suseinfo format
+<suseinfo>
+  <expire>timestamp</expire>
+  <products>
+    <id>...</id>
+  </products>
+  <kewwords>
+    <k>...</k>
+  </keywords>
+</suseinfo>
+
 */
 
 enum state {
   STATE_START,
-  STATE_REPOMD,       /* 1 */
-  STATE_DATA,         /* 2 */
-  STATE_LOCATION,     /* 3 */
-  STATE_CHECKSUM,     /* 4 */
-  STATE_TIMESTAMP,    /* 5 */
-  STATE_OPENCHECKSUM, /* 6 */
+  /* extension tags */
+  STATE_SUSEINFO,
+  STATE_EXPIRE,
+  STATE_PRODUCTS,
+  STATE_PRODUCT,
+  STATE_KEYWORDS,
+  STATE_KEYWORD,
+  /* normal repomd.xml */
+  STATE_REPOMD,
+  STATE_DATA,
+  STATE_LOCATION,
+  STATE_CHECKSUM,
+  STATE_TIMESTAMP,
+  STATE_OPENCHECKSUM,
   NUMSTATES
 };
 
@@ -83,7 +103,15 @@ struct stateswitch {
 
 /* !! must be sorted by first column !! */
 static struct stateswitch stateswitches[] = {
+  /* suseinfo tags */
   { STATE_START,       "repomd",          STATE_REPOMD, 0 },
+  { STATE_START,       "suseinfo",        STATE_SUSEINFO, 0 },  
+  { STATE_SUSEINFO,    "expire",          STATE_EXPIRE, 1 },  
+  { STATE_SUSEINFO,    "products",        STATE_PRODUCTS, 0 },  
+  { STATE_SUSEINFO,    "keywords",        STATE_KEYWORDS, 0 },  
+  { STATE_PRODUCTS,    "id",              STATE_PRODUCT, 1 },  
+  { STATE_KEYWORDS,    "k",               STATE_KEYWORD, 1 },  
+  /* standard tags */
   { STATE_REPOMD,      "data",            STATE_DATA,  0 },
   { STATE_DATA,        "location",        STATE_LOCATION, 0 },
   { STATE_DATA,        "checksum",        STATE_CHECKSUM, 1 },  
@@ -159,8 +187,6 @@ startElement(void *userData, const char *name, const char **atts)
   struct parsedata *pd = userData;
   /*Pool *pool = pd->pool;*/
   struct stateswitch *sw;
-  const char *expirestr = 0;
-  int expire = 0;
 
 #if 0
   fprintf(stderr, "start: [%d]%s\n", pd->state, name);
@@ -201,15 +227,7 @@ startElement(void *userData, const char *name, const char **atts)
         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);
-          }
-
+        /* this should be OBSOLETE soon */
         updstr = find_attr("updates", atts);
         if ( updstr != NULL )
           {
@@ -234,6 +252,12 @@ startElement(void *userData, const char *name, const char **atts)
           }
           break;
         }
+    case STATE_SUSEINFO: break;
+    case STATE_EXPIRE: break;
+    case STATE_PRODUCTS: break;
+    case STATE_PRODUCT: break;
+    case STATE_KEYWORDS: break;
+    case STATE_KEYWORD: break;
     case STATE_DATA: break;
     case STATE_LOCATION: break;
     case STATE_CHECKSUM: break;
@@ -291,6 +315,35 @@ endElement(void *userData, const char *name)
           repo_set_num(pd->repo, -1, REPOSITORY_TIMESTAMP, pd->timestamp);
         }
       break;
+    case STATE_EXPIRE:
+      {
+        int expire = 0;
+        if ( pd->content )
+          {
+            expire = atoi(pd->content);
+            if ( expire > 0 )
+              {
+                /* save the timestamp in the non solvable number 1 */
+                repo_set_num(pd->repo, -1, REPOSITORY_EXPIRE, expire);
+              }
+          }
+        break;
+      }
+    case STATE_PRODUCT:
+      {
+        if ( pd->content )
+          repo_add_poolstr_array(pd->repo, -1, REPOSITORY_PRODUCTS, pd->content);
+        break;
+      }
+    case STATE_KEYWORD:
+      {
+        if ( pd->content )
+          repo_add_poolstr_array(pd->repo, -1, REPOSITORY_KEYWORDS, pd->content);
+        break;
+      }
+    case STATE_SUSEINFO: break;
+    case STATE_PRODUCTS: break;
+    case STATE_KEYWORDS: break;
     case NUMSTATES: break;              
     default:
       break;