[Midnightbsd-cvs] src [6778] trunk/lib/libmport: add CPE column to mport bundles and the master list.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 21 13:47:20 EDT 2014


Revision: 6778
          http://svnweb.midnightbsd.org/src/?rev=6778
Author:   laffer1
Date:     2014-09-21 13:47:19 -0400 (Sun, 21 Sep 2014)
Log Message:
-----------
add CPE column to mport bundles and the master list.  bump the MPORT database version to 3 as well as the bundle version

Modified Paths:
--------------
    trunk/lib/libmport/bundle_read_install_pkg.c
    trunk/lib/libmport/create_primative.c
    trunk/lib/libmport/db.c
    trunk/lib/libmport/mport.h
    trunk/lib/libmport/mport_private.h
    trunk/lib/libmport/pkgmeta.c

Modified: trunk/lib/libmport/bundle_read_install_pkg.c
===================================================================
--- trunk/lib/libmport/bundle_read_install_pkg.c	2014-09-20 17:37:25 UTC (rev 6777)
+++ trunk/lib/libmport/bundle_read_install_pkg.c	2014-09-21 17:47:19 UTC (rev 6778)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2013 Lucas Holt
+ * Copyright (c) 2013, 2014 Lucas Holt
  * Copyright (c) 2007-2009 Chris Reinhardt
  * All rights reserved.
  *
@@ -117,7 +117,7 @@
 
   /* Insert the package meta row into the packages table (We use pack here because things might have been twiddled) */
   /* Note that this will be marked as dirty by default */  
-  if (mport_db_do(db, "INSERT INTO packages (pkg, version, origin, prefix, lang, options, comment, os_release) VALUES (%Q,%Q,%Q,%Q,%Q,%Q,%Q,%Q)", pkg->name, pkg->version, pkg->origin, pkg->prefix, pkg->lang, pkg->options, pkg->comment, pkg->os_release) != MPORT_OK)
+  if (mport_db_do(db, "INSERT INTO packages (pkg, version, origin, prefix, lang, options, comment, os_release, cpe) VALUES (%Q,%Q,%Q,%Q,%Q,%Q,%Q,%Q,%Q)", pkg->name, pkg->version, pkg->origin, pkg->prefix, pkg->lang, pkg->options, pkg->comment, pkg->os_release, pkg->cpe) != MPORT_OK)
     goto ERROR;
 
   /* Insert the assets into the master table (We do this one by one because we want to insert file 

Modified: trunk/lib/libmport/create_primative.c
===================================================================
--- trunk/lib/libmport/create_primative.c	2014-09-20 17:37:25 UTC (rev 6777)
+++ trunk/lib/libmport/create_primative.c	2014-09-21 17:47:19 UTC (rev 6778)
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/lib/libmport/create_primative.c,v 1.9 2013/03/10 03:25:35 laffer1 Exp $");
+__MBSDID("$MidnightBSD$");
 
 #include <sys/cdefs.h>
 #include <sys/stat.h>
@@ -191,7 +191,7 @@
   const char *rest  = 0;
   char *os_release;
 
-  char sql[]  = "INSERT INTO packages (pkg, version, origin, lang, prefix, comment, os_release) VALUES (?,?,?,?,?,?,?)";
+  char sql[]  = "INSERT INTO packages (pkg, version, origin, lang, prefix, comment, os_release, cpe) VALUES (?,?,?,?,?,?,?,?)";
 
   os_release = mport_get_osrelease();
   
@@ -210,7 +210,8 @@
   if (sqlite3_bind_text(stmnt, 4, pack->lang, -1, SQLITE_STATIC) != SQLITE_OK) {
     RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
   }
-  if (sqlite3_bind_text(stmnt, 5, pack->prefix, -1, SQLITE_STATIC) != SQLITE_OK) {
+  if (sqlite3_bind_text(stmnt, 5, pack->prefix, -1, SQLITE_STATIC) != SQLITE_OK)
+  {
     RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
   }
   if (sqlite3_bind_text(stmnt, 6, pack->comment, -1, SQLITE_STATIC) != SQLITE_OK) {
@@ -221,7 +222,12 @@
     free(os_release);
     RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
   }
+  if (sqlite3_bind_text(stmnt, 8, pack->cpe, -1, SQLITE_STATIC) != SQLITE_OK)
+  {
+    RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+  }
 
+
   if (sqlite3_step(stmnt) != SQLITE_DONE) {
     RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
   }

Modified: trunk/lib/libmport/db.c
===================================================================
--- trunk/lib/libmport/db.c	2014-09-20 17:37:25 UTC (rev 6777)
+++ trunk/lib/libmport/db.c	2014-09-21 17:47:19 UTC (rev 6778)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2013 Lucas Holt
+ * Copyright (c) 2013, 2014 Lucas Holt
  * Copyright (c) 2007-2009 Chris Reinhardt
  * All rights reserved.
  *
@@ -35,6 +35,7 @@
 #include "mport_private.h"
 
 static int mport_upgrade_master_schema_0to2(sqlite3 *);
+static int mport_upgrade_master_schema_2to3(sqlite3 *);
 
 
 /* mport_db_do(sqlite3 *db, const char *sql, ...)
@@ -171,7 +172,7 @@
 	RUN_SQL(db, "INSERT INTO meta VALUES (\"bundle_format_version\", " MPORT_BUNDLE_VERSION_STR ")");
 	RUN_SQL(db, sql);
 	RUN_SQL(db, "CREATE TABLE assets (pkg text not NULL, type int NOT NULL, data text, checksum text)");
-	RUN_SQL(db, "CREATE TABLE packages (pkg text NOT NULL, version text NOT NULL, origin text NOT NULL, lang text, options text, prefix text NOT NULL, comment text, os_release text NOT NULL)");
+	RUN_SQL(db, "CREATE TABLE packages (pkg text NOT NULL, version text NOT NULL, origin text NOT NULL, lang text, options text, prefix text NOT NULL, comment text, os_release text NOT NULL, cpe text NOT NULL)");
 	RUN_SQL(db, "CREATE TABLE conflicts (pkg text NOT NULL, conflict_pkg text NOT NULL, conflict_version text NOT NULL)");
 	RUN_SQL(db, "CREATE TABLE depends (pkg text NOT NULL, depend_pkgname text NOT NULL, depend_pkgversion text, depend_port text NOT NULL)");
 	RUN_SQL(db, "CREATE TABLE categories (pkg text NOT NULL, category text NOT NULL)");
@@ -187,9 +188,13 @@
 		case 0:
 		case 1:
 			mport_upgrade_master_schema_0to2(db);
+			mport_upgrade_master_schema_2to3(db);
 			mport_set_database_version(db);
 		case 2:
+			mport_upgrade_master_schema_2to3(db);
 			break;
+		case 3:
+			break;
 		default:
 			RETURN_ERROR(MPORT_ERR_FATAL, "Invalid master database version");
 	}
@@ -207,11 +212,20 @@
 	return (MPORT_OK);
 }
 
+static int
+mport_upgrade_master_schema_2to3(sqlite3 *db)
+{
+
+        RUN_SQL(db, "ALTER TABLE packages ADD COLUMN cpe text;");
+
+        return (MPORT_OK);
+}
+
 int
 mport_generate_master_schema(sqlite3 *db) 
 {
 
-	RUN_SQL(db, "CREATE TABLE IF NOT EXISTS packages (pkg text NOT NULL, version text NOT NULL, origin text NOT NULL, prefix text NOT NULL, lang text, options text, status text default 'dirty', comment text, os_release text)");
+	RUN_SQL(db, "CREATE TABLE IF NOT EXISTS packages (pkg text NOT NULL, version text NOT NULL, origin text NOT NULL, prefix text NOT NULL, lang text, options text, status text default 'dirty', comment text, os_release text, cpe text)");
 	RUN_SQL(db, "CREATE UNIQUE INDEX IF NOT EXISTS packages_pkg ON packages (pkg)");
 	RUN_SQL(db, "CREATE INDEX IF NOT EXISTS packages_origin ON packages (origin)");
 

Modified: trunk/lib/libmport/mport.h
===================================================================
--- trunk/lib/libmport/mport.h	2014-09-20 17:37:25 UTC (rev 6777)
+++ trunk/lib/libmport/mport.h	2014-09-21 17:47:19 UTC (rev 6778)
@@ -1,6 +1,6 @@
 /* $MidnightBSD$
  *
- * Copyright (c) 2013 Lucas Holt
+ * Copyright (c) 2013, 2014 Lucas Holt
  * Copyright (c) 2007-2009 Chris Reinhardt
  * All rights reserved.
  *
@@ -112,6 +112,7 @@
   char *origin;
   char **categories;
   char *os_release;
+  char *cpe;
 } mportPackageMeta;  
 
 

Modified: trunk/lib/libmport/mport_private.h
===================================================================
--- trunk/lib/libmport/mport_private.h	2014-09-20 17:37:25 UTC (rev 6777)
+++ trunk/lib/libmport/mport_private.h	2014-09-21 17:47:19 UTC (rev 6778)
@@ -42,9 +42,9 @@
 
 #define MPORT_PUBLIC_API 
 
-#define MPORT_MASTER_VERSION 2
-#define MPORT_BUNDLE_VERSION 2
-#define MPORT_BUNDLE_VERSION_STR "2"
+#define MPORT_MASTER_VERSION 3
+#define MPORT_BUNDLE_VERSION 3
+#define MPORT_BUNDLE_VERSION_STR "3"
 
 /* callback syntaxtic sugar */
 void mport_call_msg_cb(mportInstance *, const char *, ...);

Modified: trunk/lib/libmport/pkgmeta.c
===================================================================
--- trunk/lib/libmport/pkgmeta.c	2014-09-20 17:37:25 UTC (rev 6777)
+++ trunk/lib/libmport/pkgmeta.c	2014-09-21 17:47:19 UTC (rev 6778)
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/lib/libmport/pkgmeta.c,v 1.9 2012/04/10 22:11:33 laffer1 Exp $");
+__MBSDID("$MidnightBSD$");
 
 #include <stdlib.h>
 #include <string.h>
@@ -69,6 +69,8 @@
   pack->origin = NULL;
   free(pack->os_release);
   pack->os_release = NULL;
+  free(pack->cpe);
+  pack->cpe = NULL;
  
 
   i = 0;
@@ -128,7 +130,7 @@
     RETURN_ERROR(MPORT_ERR_FATAL, "stub database contains no packages.");
   }
     
-  if (mport_db_prepare(db, &stmt, "SELECT pkg, version, origin, lang, prefix, comment, os_release FROM stub.packages") != MPORT_OK) {
+  if (mport_db_prepare(db, &stmt, "SELECT pkg, version, origin, lang, prefix, comment, os_release, cpe FROM stub.packages") != MPORT_OK) {
     sqlite3_finalize(stmt);
     RETURN_CURRENT_ERROR;
   }
@@ -197,7 +199,7 @@
     return MPORT_OK;
   }
 
-  if (mport_db_prepare(db, &stmt, "SELECT pkg, version, origin, lang, prefix, comment, os_release FROM packages WHERE %s", where) != MPORT_OK) {
+  if (mport_db_prepare(db, &stmt, "SELECT pkg, version, origin, lang, prefix, comment, os_release, cpe FROM packages WHERE %s", where) != MPORT_OK) {
     sqlite3_finalize(stmt);
     RETURN_CURRENT_ERROR;
   }
@@ -242,7 +244,7 @@
     return MPORT_OK;
   }
 
-  if (mport_db_prepare(db, &stmt, "SELECT pkg, version, origin, lang, prefix, comment, os_release FROM packages ORDER BY pkg, version") != MPORT_OK) {
+  if (mport_db_prepare(db, &stmt, "SELECT pkg, version, origin, lang, prefix, comment, os_release, cpe FROM packages ORDER BY pkg, version") != MPORT_OK) {
     sqlite3_finalize(stmt);
     RETURN_CURRENT_ERROR;
   }
@@ -287,7 +289,7 @@
   }
 
   if (mport_db_prepare(mport->db, &stmt, 
-      "SELECT packages.pkg, packages.version, packages.origin, packages.lang, packages.prefix, packages.comment, packages.os_release FROM packages,depends WHERE packages.pkg=depends.depend_pkgname AND depends.pkg=%Q", 
+      "SELECT packages.pkg, packages.version, packages.origin, packages.lang, packages.prefix, packages.comment, packages.os_release, packages.cpe FROM packages,depends WHERE packages.pkg=depends.depend_pkgname AND depends.pkg=%Q", 
       pkg->name) != MPORT_OK) {
     sqlite3_finalize(stmt);
     RETURN_CURRENT_ERROR;
@@ -494,6 +496,7 @@
       RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
   }
 
+  /* os_release */
   if ((tmp = sqlite3_column_text(stmt, 6)) == NULL) 
     return MPORT_OK; /*  XXX: new field..
     RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
@@ -501,6 +504,15 @@
 
   if ((pack->os_release = strdup(tmp)) == NULL)
     RETURN_ERROR(MPORT_ERR_FATAL,"Out of memory.");
+
+  /* CPE */
+  if ((tmp = sqlite3_column_text(stmt, 7)) == NULL) {
+      return MPORT_OK; /* XXX: new field..
+      RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
+      */
+  } 
+  if ((pack->cpe = strdup(tmp)) == NULL)
+    RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
   
   return MPORT_OK;
 }



More information about the Midnightbsd-cvs mailing list