[Midnightbsd-cvs] src [7445] trunk/lib/libmport: add list functionality to index.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Feb 17 11:35:35 EST 2016


Revision: 7445
          http://svnweb.midnightbsd.org/src/?rev=7445
Author:   laffer1
Date:     2016-02-17 11:34:34 -0500 (Wed, 17 Feb 2016)
Log Message:
-----------
add list functionality to index. We can now list everything in the index via public api

Modified Paths:
--------------
    trunk/lib/libmport/Makefile
    trunk/lib/libmport/index.c
    trunk/lib/libmport/mport.h

Modified: trunk/lib/libmport/Makefile
===================================================================
--- trunk/lib/libmport/Makefile	2016-02-05 15:15:30 UTC (rev 7444)
+++ trunk/lib/libmport/Makefile	2016-02-17 16:34:34 UTC (rev 7445)
@@ -8,7 +8,7 @@
 		update_primative.c bundle_read_update_pkg.c pkgmeta.c \
 		fetch.c index.c index_depends.c install.c clean.c setting.c  \
 		stats.c verify.c lock.c
-INCS=		mport.h 
+INCS=		mport.h mport_dispatch.h
 
 CFLAGS+=	-I${.CURDIR} -fblocks -g
 SHLIB_MAJOR=	1

Modified: trunk/lib/libmport/index.c
===================================================================
--- trunk/lib/libmport/index.c	2016-02-05 15:15:30 UTC (rev 7444)
+++ trunk/lib/libmport/index.c	2016-02-17 16:34:34 UTC (rev 7445)
@@ -257,7 +257,8 @@
  * is responsible for freeing the memory allocated.  See
  * mport_index_entry_free_vec()
  */
-MPORT_PUBLIC_API int mport_index_lookup_pkgname(mportInstance *mport, const char *pkgname, mportIndexEntry ***entry_vec)
+MPORT_PUBLIC_API int 
+mport_index_lookup_pkgname(mportInstance *mport, const char *pkgname, mportIndexEntry ***entry_vec)
 {
   char *lookup = NULL;
   int count, i = 0, step;
@@ -349,7 +350,8 @@
  *
  * indexEntries is set to an empty allocated list and MPORT_OK is returned if no packages where found.
  */
-MPORT_PUBLIC_API int mport_index_search(mportInstance *mport, mportIndexEntry ***entry_vec, const char *fmt, ...)
+MPORT_PUBLIC_API int 
+mport_index_search(mportInstance *mport, mportIndexEntry ***entry_vec, const char *fmt, ...)
 {
   va_list args;
   sqlite3_stmt *stmt;
@@ -431,6 +433,77 @@
 }
 
 
+MPORT_PUBLIC_API int 
+mport_index_list(mportInstance *mport, mportIndexEntry ***entry_vec)
+{
+  sqlite3_stmt *stmt;
+  int ret = MPORT_OK, len;
+  int i = 0, step;
+  sqlite3 *db = mport->db;
+  mportIndexEntry **e;
+
+  if (mport_db_prepare(db, &stmt, "SELECT count(*) FROM idx.packages") != MPORT_OK) {
+    sqlite3_finalize(stmt);
+    RETURN_CURRENT_ERROR;
+  }
+
+  if (sqlite3_step(stmt) != SQLITE_ROW) {
+    sqlite3_finalize(stmt);
+    RETURN_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
+  }
+
+  len = sqlite3_column_int(stmt, 0);
+  sqlite3_finalize(stmt);
+
+  e = (mportIndexEntry **)calloc(len + 1, sizeof(mportIndexEntry *));
+  *entry_vec = e;
+
+  if (len == 0) {
+    return MPORT_OK;
+  }
+
+  if (mport_db_prepare(db, &stmt, "SELECT pkg, version, comment, bundlefile, license, hash FROM idx.packages") != MPORT_OK) {
+    sqlite3_finalize(stmt);
+    RETURN_CURRENT_ERROR;
+  }
+
+  while (1) {
+    step = sqlite3_step(stmt);
+
+    if (step == SQLITE_ROW) {
+      if ((e[i] = (mportIndexEntry *)calloc(1, sizeof(mportIndexEntry))) == NULL) {
+        ret = MPORT_ERR_FATAL;
+        break;
+      }
+
+      e[i]->pkgname    = strdup(sqlite3_column_text(stmt, 0));
+      e[i]->version    = strdup(sqlite3_column_text(stmt, 1));
+      e[i]->comment    = strdup(sqlite3_column_text(stmt, 2));
+      e[i]->bundlefile = strdup(sqlite3_column_text(stmt, 3));
+      e[i]->license    = strdup(sqlite3_column_text(stmt, 4));
+      e[i]->hash       = strdup(sqlite3_column_text(stmt, 5));
+
+      if (e[i]->pkgname == NULL || e[i]->version == NULL || e[i]->comment == NULL || e[i]->license == NULL || e[i]->bundlefile == NULL) {
+        ret = MPORT_ERR_FATAL;
+        break;
+      }
+
+      i++;
+    } else if (step == SQLITE_DONE) {
+      e[i] = NULL;
+      break;
+    } else {
+      ret = SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
+      break;
+    }
+  }
+
+  sqlite3_finalize(stmt);
+
+  return ret;
+}
+
+
 static int lookup_alias(mportInstance *mport, const char *query, char **result) 
 {
   sqlite3_stmt *stmt;

Modified: trunk/lib/libmport/mport.h
===================================================================
--- trunk/lib/libmport/mport.h	2016-02-05 15:15:30 UTC (rev 7444)
+++ trunk/lib/libmport/mport.h	2016-02-17 16:34:34 UTC (rev 7445)
@@ -141,6 +141,7 @@
 
 int mport_index_load(mportInstance *);
 int mport_index_get(mportInstance *);
+int mport_index_list(mportInstance *, mportIndexEntry ***);
 int mport_index_lookup_pkgname(mportInstance *, const char *, mportIndexEntry ***);
 int mport_index_search(mportInstance *, mportIndexEntry ***, const char *, ...);
 void mport_index_entry_free_vec(mportIndexEntry **);



More information about the Midnightbsd-cvs mailing list