[Midnightbsd-cvs] src [7499] trunk/lib/libmport: Create an mport_info public api
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Thu Mar 24 21:04:15 EDT 2016
Revision: 7499
http://svnweb.midnightbsd.org/src/?rev=7499
Author: laffer1
Date: 2016-03-24 21:04:13 -0400 (Thu, 24 Mar 2016)
Log Message:
-----------
Create an mport_info public api
Modified Paths:
--------------
trunk/lib/libmport/Makefile
trunk/lib/libmport/mport.h
Added Paths:
-----------
trunk/lib/libmport/info.c
Modified: trunk/lib/libmport/Makefile
===================================================================
--- trunk/lib/libmport/Makefile 2016-03-24 03:53:54 UTC (rev 7498)
+++ trunk/lib/libmport/Makefile 2016-03-25 01:04:13 UTC (rev 7499)
@@ -1,14 +1,15 @@
# $MidnightBSD$
-LIB= mport
-SRCS= bundle_write.c bundle_read.c plist.c create_primative.c db.c \
- dispatch.c util.c error.c install_primative.c instance.c \
+LIB= mport
+SRCS= bundle_write.c bundle_read.c plist.c create_primative.c db.c \
+ dispatch.c util.c error.c \
+ info.c install_primative.c instance.c \
version_cmp.c check_preconditions.c delete_primative.c \
default_cbs.c merge_primative.c bundle_read_install_pkg.c \
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 mport_dispatch.h
+ fetch.c index.c index_depends.c install.c clean.c setting.c \
+ stats.c verify.c lock.c
+INCS= mport.h mport_dispatch.h
CFLAGS+= -I${.CURDIR} -fblocks -g
SHLIB_MAJOR= 1
Added: trunk/lib/libmport/info.c
===================================================================
--- trunk/lib/libmport/info.c (rev 0)
+++ trunk/lib/libmport/info.c 2016-03-25 01:04:13 UTC (rev 7499)
@@ -0,0 +1,101 @@
+/*-
+ * Copyright (c) 2015, 2016 Lucas Holt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__MBSDID("$MidnightBSD$");
+
+#include "mport.h"
+#include "mport_private.h"
+#include <stdlib.h>
+#include <string.h>
+#include <err.h>
+#include <unistd.h>
+
+
+MPORT_PUBLIC_API char *
+mport_info(mportInstance *mport, const char *packageName) {
+ mportIndexEntry **indexEntry;
+ mportPackageMeta **packs;
+ char *status, *origin;
+ char *os_release;
+ char *cpe;
+ int locked = 0;
+ char *info_text = NULL;
+
+ if (packageName == NULL) {
+ SET_ERROR(MPORT_ERR_FATAL, "Package name not found.");
+ return (NULL);
+ }
+
+
+ if (mport_index_lookup_pkgname(mport, packageName, &indexEntry) != MPORT_OK) {
+ return (NULL);
+ }
+
+ if (indexEntry == NULL || *indexEntry == NULL) {
+ SET_ERROR(MPORT_ERR_FATAL, "Could not resolve package.");
+ return (NULL);
+ }
+
+ if (mport_pkgmeta_search_master(mport, &packs, "pkg=%Q", packageName) != MPORT_OK) {
+ return (NULL);
+ }
+
+ if (packs == NULL) {
+ status = strdup("N/A");
+ origin = strdup("");
+ os_release = strdup("");
+ cpe = strdup("");
+ } else {
+ status = (*packs)->version;
+ origin = (*packs)->origin;
+ os_release = (*packs)->os_release;
+ cpe = (*packs)->cpe;
+ locked = (*packs)->locked;
+ }
+
+ asprintf(&info_text, "%s\nlatest: %s\ninstalled: %s\nlicense: %s\norigin: %s\nos: %s\n\n%s\ncpe: %s\nlocked: %s\n",
+ (*indexEntry)->pkgname,
+ (*indexEntry)->version,
+ status,
+ (*indexEntry)->license,
+ origin,
+ os_release,
+ (*indexEntry)->comment,
+ cpe,
+ locked ? "yes" : "no");
+
+ if (packs == NULL) {
+ free(status);
+ free(origin);
+ free(os_release);
+ free(cpe);
+ } else
+ mport_pkgmeta_vec_free(packs);
+
+ mport_index_entry_free_vec(indexEntry);
+ return info_text;
+}
\ No newline at end of file
Modified: trunk/lib/libmport/mport.h
===================================================================
--- trunk/lib/libmport/mport.h 2016-03-24 03:53:54 UTC (rev 7498)
+++ trunk/lib/libmport/mport.h 2016-03-25 01:04:13 UTC (rev 7499)
@@ -160,6 +160,10 @@
void mport_index_depends_free_vec(mportDependsEntry **);
void mport_index_depends_free(mportDependsEntry *);
+
+/* Info */
+char * mport_info(mportInstance *mport, const char *packageName);
+
/* Package creation */
typedef struct {
More information about the Midnightbsd-cvs
mailing list