From 6b5fc2297de3d0f89e7cb3dc936726e6cf575607 Mon Sep 17 00:00:00 2001
From: Cloudef <mailRoxas@gmail.com>
Date: Tue, 30 Aug 2011 15:11:14 +0300
Subject: [PATCH] Add version && package version support to discovery

---
 include/pnd_discovery.h |    8 ++++++++
 include/pnd_pxml.h      |    8 ++++++++
 lib/pnd_discovery.c     |   32 ++++++++++++++++++++++++++++++++
 lib/pnd_pxml.c          |   32 ++++++++++++++++++++++++++++++++
 lib/pnd_tinyxml.cpp     |   28 ++++++++++++++++++++++++++++
 5 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/include/pnd_discovery.h b/include/pnd_discovery.h
index 237ef62..c241a94 100644
--- a/include/pnd_discovery.h
+++ b/include/pnd_discovery.h
@@ -80,6 +80,14 @@ typedef struct {
   char *info_name;      // should be a struct..
   char *info_filename;
   char *info_type;
+  char *version_major;
+  char *version_minor;
+  char *version_release;
+  char *version_build;
+  char *package_version_major;
+  char *package_version_minor;
+  char *package_version_release;
+  char *package_version_build;
 } pnd_disco_t;
 
 void pnd_disco_destroy ( pnd_disco_t *p ); // a function name that simply could not be avoided
diff --git a/include/pnd_pxml.h b/include/pnd_pxml.h
index 15b3e96..a7eec6d 100644
--- a/include/pnd_pxml.h
+++ b/include/pnd_pxml.h
@@ -96,6 +96,10 @@ char *pnd_pxml_get_mkdir ( pnd_pxml_handle h );
 char *pnd_pxml_get_info_name ( pnd_pxml_handle h );
 char *pnd_pxml_get_info_type ( pnd_pxml_handle h );
 char *pnd_pxml_get_info_src ( pnd_pxml_handle h );
+char *pnd_pxml_get_package_version_major ( pnd_pxml_handle h );
+char *pnd_pxml_get_package_version_minor ( pnd_pxml_handle h );
+char *pnd_pxml_get_package_version_release ( pnd_pxml_handle h );
+char *pnd_pxml_get_package_version_build ( pnd_pxml_handle h );
 
 // for 'set' functions, pass NULL value to delete existing value without setting new one
 void pnd_pxml_set_app_name ( pnd_pxml_handle h, char *v );
@@ -172,6 +176,10 @@ typedef struct
         char *info_name;      // should be a struct..
         char *info_filename;
         char *info_type;
+        char *package_version_major;
+        char *package_version_minor;
+        char *package_version_release;
+        char *package_version_build;
 
 }  pnd_pxml_t;
 
diff --git a/lib/pnd_discovery.c b/lib/pnd_discovery.c
index 84376e9..fd12224 100644
--- a/lib/pnd_discovery.c
+++ b/lib/pnd_discovery.c
@@ -53,6 +53,14 @@ void pnd_disco_destroy ( pnd_disco_t *p ) {
   if ( p -> info_filename ) {  free ( p -> info_filename );       }
   if ( p -> preview_pic1 )  {  free ( p -> preview_pic1 );     }
   if ( p -> preview_pic2 )  {  free ( p -> preview_pic2 );     }
+  if ( p -> version_major ) {  free ( p -> version_major );    }
+  if ( p -> version_minor ) {  free ( p -> version_minor );    }
+  if ( p -> version_release ) {free ( p -> version_release );  }
+  if ( p -> version_build ) {  free ( p -> version_build );    }
+  if ( p -> package_version_major ) { free ( p -> package_version_major ); }
+  if ( p -> package_version_minor ) { free ( p -> package_version_minor ); }
+  if ( p -> package_version_release ) { free ( p -> package_version_release ); }
+  if ( p -> package_version_build ) { free ( p -> package_version_build ); }
   return;
 }
 
@@ -303,6 +311,30 @@ static int pnd_disco_callback ( const char *fpath, const struct stat *sb,
       if ( pnd_pxml_get_info_type ( pxmlh ) ) {
 	p -> info_type = strdup ( pnd_pxml_get_info_type ( pxmlh ) );
       }
+      if ( pnd_pxml_get_version_major ( pxmlh ) ) {
+   p -> version_major = strdup ( pnd_pxml_get_version_major ( pxmlh ) );
+      }
+      if ( pnd_pxml_get_version_minor ( pxmlh ) ) {
+   p -> version_minor = strdup ( pnd_pxml_get_version_minor ( pxmlh ) );
+      }
+      if ( pnd_pxml_get_version_release ( pxmlh ) ) {
+   p -> version_release = strdup ( pnd_pxml_get_version_release ( pxmlh ) );
+      }
+      if ( pnd_pxml_get_version_build ( pxmlh ) ) {
+   p -> version_build = strdup ( pnd_pxml_get_version_build ( pxmlh ) );
+      }
+      if ( pnd_pxml_get_package_version_major ( pxmlh ) ) {
+	p -> package_version_major = strdup ( pnd_pxml_get_package_version_major ( pxmlh ) );
+      }
+      if ( pnd_pxml_get_package_version_minor ( pxmlh ) ) {
+   p -> package_version_minor = strdup ( pnd_pxml_get_package_version_minor ( pxmlh ) );
+      }
+      if ( pnd_pxml_get_package_version_release ( pxmlh ) ) {
+   p -> package_version_release = strdup ( pnd_pxml_get_package_version_release ( pxmlh ) );
+      }
+      if ( pnd_pxml_get_package_version_build ( pxmlh ) ) {
+   p -> package_version_build = strdup ( pnd_pxml_get_package_version_build ( pxmlh ) );
+      }
 
       // look for any PXML overrides, if requested
       if ( disco_overrides ) {
diff --git a/lib/pnd_pxml.c b/lib/pnd_pxml.c
index 3a9406d..29e996d 100644
--- a/lib/pnd_pxml.c
+++ b/lib/pnd_pxml.c
@@ -204,6 +204,18 @@ void pnd_pxml_delete ( pnd_pxml_handle h ) {
   if ( p -> execargs ) {
     free ( p -> execargs );
   }
+  if ( p -> package_version_major ) {
+    free ( p -> package_version_major );
+  }
+  if ( p -> package_version_minor ) {
+    free ( p -> package_version_minor );
+  }
+  if ( p -> package_version_release ) {
+    free ( p -> package_version_release );
+  }
+  if ( p -> package_version_build ) {
+    free ( p -> package_version_build );
+  }
 
   free(p); /*very important!*/
 
@@ -585,6 +597,26 @@ char *pnd_pxml_get_mkdir ( pnd_pxml_handle h ) {
   return ( p -> mkdir_sp );
 }
 
+char *pnd_pxml_get_package_version_major ( pnd_pxml_handle h ) {
+   pnd_pxml_t *p = (pnd_pxml_t*) h;
+   return ( p -> package_version_major );
+}
+
+char *pnd_pxml_get_package_version_minor ( pnd_pxml_handle h ) {
+   pnd_pxml_t *p = (pnd_pxml_t*) h;
+   return ( p -> package_version_minor );
+}
+
+char *pnd_pxml_get_package_version_release ( pnd_pxml_handle h ) {
+   pnd_pxml_t *p = (pnd_pxml_t*) h;
+   return ( p -> package_version_release );
+}
+
+char *pnd_pxml_get_package_version_build ( pnd_pxml_handle h ) {
+   pnd_pxml_t *p = (pnd_pxml_t*) h;
+   return ( p -> package_version_build );
+}
+
 unsigned char pnd_pxml_is_affirmative ( char *v ) {
 
   if ( ! v ) {
diff --git a/lib/pnd_tinyxml.cpp b/lib/pnd_tinyxml.cpp
index 8bb7436..577aef0 100644
--- a/lib/pnd_tinyxml.cpp
+++ b/lib/pnd_tinyxml.cpp
@@ -225,9 +225,21 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
   // workaround for package ID's used by some package managers
   // get the package ID and store it for each application
   char* package_id = NULL;
+  char* package_version_major = NULL;
+  char* package_version_minor = NULL;
+  char* package_version_release = NULL;
+  char* package_version_build = NULL;
   pElem = hRoot.FirstChild ( PND_PXML_ENAME_PACKAGE ).Element();
   if ( pElem ) {
 	package_id = pnd_pxml_get_attribute ( pElem, PND_PXML_ATTRNAME_PACKAGE_ID );
+   TiXmlHandle pRoot = TiXmlHandle( pElem );
+   if ( (pElem = pRoot.FirstChild(PND_PXML_ENAME_VERSION).Element()) )
+   {
+      package_version_major   = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_VERMAJOR);
+      package_version_minor   = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_VERMINOR);
+      package_version_release = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_VERREL);
+      package_version_build   = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_VERBUILD);
+   }
   }
 
   // move to applications element then
@@ -257,6 +269,14 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
     // give application the package id, if there is one
     if( package_id )
       app -> package_id               = strdup(package_id);
+    if( package_version_major )
+      app -> package_version_major    = strdup(package_version_major);
+    if( package_version_minor )
+      app -> package_version_minor    = strdup(package_version_minor);
+    if( package_version_release )
+      app -> package_version_release  = strdup(package_version_release);
+    if( package_version_build )
+      app -> package_version_build    = strdup(package_version_build);
 
     //Get unique ID first.
     if ( appwrappermode ) {
@@ -508,6 +528,14 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
 
   if( package_id )
      free(package_id);
+  if( package_version_major )
+     free(package_version_major);
+  if( package_version_minor )
+     free(package_version_minor);
+  if( package_version_release )
+     free(package_version_release);
+  if( package_version_build )
+     free(package_version_build);
 
   return (1);
 }
-- 
1.7.6.1

