[Midnightbsd-cvs] src: lib/libmport: Start of libmport.
ctriv at midnightbsd.org
ctriv at midnightbsd.org
Sun Sep 23 18:30:52 EDT 2007
Log Message:
-----------
Start of libmport. At the moment all it can do is a make a tmpdir with the
package-meta database. Soon we'll pull in libarchive and start to make some
packages.
Added Files:
-----------
src/lib/libmport:
Makefile (r1.1)
create_pkg.c (r1.1)
db_schema.c (r1.1)
error.c (r1.1)
plist.c (r1.1)
util.c (r1.1)
-------------- next part --------------
--- /dev/null
+++ lib/libmport/plist.c
@@ -0,0 +1,198 @@
+/*-
+ * Copyright (c) 2007 Chris Reinhardt
+ * 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.
+ *
+ * $MidnightBSD: src/lib/libmport/plist.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $
+ */
+
+
+
+#include <sys/cdefs.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "mport.h"
+
+__MBSDID("$MidnightBSD: src/lib/libmport/plist.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $");
+
+#define CMND_MAGIC_COOKIE '@'
+#define STRING_EQ(r,l) (strcmp((r),(l)) == 0)
+
+static mportPlistEntryType parse_command(const char*);
+
+/* Do everything needed to set up a new plist. Always use this to create a plist,
+ * don't go off and do it yourself.
+ */
+mportPlist* mport_new_plist()
+{
+ mportPlist *list = (mportPlist*)malloc(sizeof(mportPlist));
+ STAILQ_INIT(list);
+ return list;
+}
+
+
+/* free all the entryes in the list, and then the list itself. */
+void mport_free_plist(mportPlist *list)
+{
+ mportPlistEntry *n;
+
+ while (!STAILQ_EMPTY(list)) {
+ n = STAILQ_FIRST(list);
+ STAILQ_REMOVE_HEAD(list, next);
+ free(n->data);
+ free(n);
+ }
+
+ free(list);
+}
+
+
+/* Parsers the contenst of the file and returns a plist data structure.
+ *
+ * Returns NULL on failure.
+ */
+int mport_parse_plist_file(FILE *fp, mportPlist *list)
+{
+ size_t length;
+ char *line;
+
+ while ((line = fgetln(fp, &length)) != NULL) {
+ if (feof(fp)) {
+ /* File didn't end in \n, get an exta byte so that the next step doesn't
+ wack the last char in the string. */
+ length++;
+ if ((line = realloc(line, length)) == NULL) {
+ /* warn: out of mem */
+ return 1;
+ }
+ }
+
+ if (length == 1)
+ /* This is almost certainly a blank line. skip it */
+ continue;
+
+
+ /* change the last \n to \0 */
+ *(line + length - 1) = 0;
+
+ mportPlistEntry *entry = (mportPlistEntry *)malloc(sizeof(mportPlistEntry));
+
+ if (entry == NULL) {
+ // warn: out of mem!
+ return 1;
+ }
+
+ if (*line == CMND_MAGIC_COOKIE) {
+ line++;
+ char *cmnd = strsep(&line, " \t");
+
+ if (cmnd == NULL) {
+ // warn: malformed plist
+ return 1;
+ }
+
+ entry->type = parse_command(cmnd);
+ } else {
+ entry->type = PLIST_FILE;
+ }
+
+
+ if (line == NULL) {
+ /* line was just a directive, no data */
+ entry->data = NULL;
+ } else {
+ if (entry->type == PLIST_COMMENT) {
+ if (!strncmp(line, "ORIGIN:", 7)) {
+ line += 7;
+ entry->type = PLIST_ORIGIN;
+ } else if (!strncmp(line, "DEPORIGIN:", 10)) {
+ line += 10;
+ entry->type = PLIST_DEPORIGIN;
+ }
+ }
+
+ entry->data = (char *)malloc(strlen(line) + 1);
+ if (entry->data == NULL) {
+ /* warn: out of mem */
+ return 1;
+ }
+
+ strlcpy(entry->data, line, (strlen(line) + 1));
+ }
+
+ STAILQ_INSERT_TAIL(list, entry, next);
+ }
+
+ return 0;
+}
+
+
+
+static mportPlistEntryType parse_command(const char *s)
+{
+ /* This is in a rough frequency order */
+ if (STRING_EQ(s, "comment"))
+ return PLIST_COMMENT;
+ if (STRING_EQ(s, "exec"))
+ return PLIST_EXEC;
+ if (STRING_EQ(s, "unexec"))
+ return PLIST_UNEXEC;
+ if (STRING_EQ(s, "dirrm"))
+ return PLIST_DIRRM;
+ if (STRING_EQ(s, "dirrmtry"))
+ return PLIST_DIRRMTRY;
+ if (STRING_EQ(s, "cwd") || STRING_EQ(s, "cd"))
+ return PLIST_CWD;
+ if (STRING_EQ(s, "srcdir"))
+ return PLIST_SRC;
+ if (STRING_EQ(s, "mode"))
+ return PLIST_CHMOD;
+ if (STRING_EQ(s, "owner"))
+ return PLIST_CHOWN;
+ if (STRING_EQ(s, "group"))
+ return PLIST_CHGRP;
+ if (STRING_EQ(s, "noinst"))
+ return PLIST_NOINST;
+ if (STRING_EQ(s, "ignore"))
+ return PLIST_IGNORE;
+ if (STRING_EQ(s, "ignore_inst"))
+ return PLIST_IGNORE_INST;
+ if (STRING_EQ(s, "name"))
+ return PLIST_NAME;
+ if (STRING_EQ(s, "display"))
+ return PLIST_DISPLAY;
+ if (STRING_EQ(s, "pkgdep"))
+ return PLIST_PKGDEP;
+ if (STRING_EQ(s, "conflicts"))
+ return PLIST_CONFLICTS;
+ if (STRING_EQ(s, "mtree"))
+ return PLIST_MTREE;
+ if (STRING_EQ(s, "option"))
+ return PLIST_OPTION;
+
+ return PLIST_INVALID;
+}
+
+
+
--- /dev/null
+++ lib/libmport/util.c
@@ -0,0 +1,61 @@
+/*-
+ * Copyright (c) 2007 Chris Reinhardt
+ * 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.
+ *
+ * $MidnightBSD: src/lib/libmport/util.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $
+ */
+
+
+
+#include <sqlite3.h>
+#include <stdlib.h>
+#include "mport.h"
+
+__MBSDID("$MidnightBSD: src/lib/libmport/util.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $");
+
+/* Package meta-data creation and destruction */
+mportPackageMeta* mport_new_packagemeta()
+{
+ return (mportPackageMeta *)malloc(sizeof(mportPackageMeta));
+}
+
+void mport_free_packagemeta(mportPackageMeta *pack)
+{
+ free(pack->pkg_filename);
+ free(pack->comment);
+ free(pack->sourcedir);
+ free(pack->desc);
+ free(pack->prefix);
+ free(*(pack->depends));
+ free(pack->depends);
+ free(pack->mtree);
+ free(pack->origin);
+ free(*(pack->conflicts));
+ free(pack->conflicts);
+ free(pack->pkginstall);
+ free(pack->pkgdeinstall);
+ free(pack->pkgmessage);
+ free(pack->req_script);
+ free(pack);
+}
--- /dev/null
+++ lib/libmport/error.c
@@ -0,0 +1,80 @@
+/*-
+ * Copyright (c) 2007 Chris Reinhardt
+ * 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.
+ *
+ * $MidnightBSD: src/lib/libmport/error.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $
+ */
+
+
+#include "mport.h"
+#include <stdlib.h>
+#include <string.h>
+
+__MBSDID("$MidnightBSD: src/lib/libmport/error.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $");
+
+static int err;
+static char err_msg[256];
+
+/* This goes with the error codes in mport.h */
+static char *mport_err_defaults[] = {
+ NULL,
+ "Out of memory.",
+ "File I/O Error.",
+ "Malformed packing list.",
+ "SQLite error.",
+ "File not found."
+};
+
+
+int mport_err_code()
+{
+ return err;
+}
+
+char * mport_err_string()
+{
+ size_t len = strlen(err_msg);
+ char *copy = (char *)malloc(len + 1);
+
+ if (copy == NULL) {
+ fprintf(stderr, "Fatal error: unable to allocate memory for error string: %s\n", err_msg);
+ exit(255);
+ }
+
+ strlcpy(copy, err_msg, len + 1);
+
+ return copy;
+}
+
+int mport_set_err(int code, const char *msg)
+{
+ err = code;
+ if (msg != NULL) {
+ strlcpy(err_msg, msg, sizeof(err_msg));
+ } else {
+ strlcpy(err_msg, mport_err_defaults[code], sizeof(mport_err_defaults[code]));
+ }
+ return code;
+}
+
--- /dev/null
+++ lib/libmport/create_pkg.c
@@ -0,0 +1,215 @@
+/*-
+ * Copyright (c) 2007 Chris Reinhardt
+ * 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.
+ *
+ * $MidnightBSD: src/lib/libmport/create_pkg.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $
+ */
+
+
+
+#include <sys/cdefs.h>
+#include <sys/time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sqlite3.h>
+#include <errno.h>
+#include <md5.h>
+#include "mport.h"
+
+__MBSDID("$MidnightBSD: src/lib/libmport/create_pkg.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $");
+
+#define PACKAGE_DB_FILENAME "+CONTENTS.db"
+
+static int create_package_db(sqlite3 **);
+static int create_plist(sqlite3 *, mportPlist *, mportPackageMeta *);
+static int create_meta(sqlite3 *, mportPackageMeta *);
+static int tar_files(mportPlist *, mportPackageMeta *);
+static int clean_up(const char *);
+
+int mport_create_pkg(mportPlist *plist, mportPackageMeta *pack)
+{
+ /* create a temp dir to hold our meta files. */
+ char dirtmpl[] = "/tmp/mport.XXXXXXXX";
+ char *tmpdir = mkdtemp(dirtmpl);
+
+ int ret = 0;
+ sqlite3 *db;
+
+ if (tmpdir == NULL)
+ RETURN_ERROR(MPORT_ERR_FILEIO, strerror(errno));
+
+ if (chdir(tmpdir) != 0)
+ RETURN_ERROR(MPORT_ERR_FILEIO, strerror(errno));
+
+ if ((ret = create_package_db(&db)) != MPORT_OK)
+ return ret;
+
+ if ((ret = create_plist(db, plist, pack)) != MPORT_OK)
+ return ret;
+
+ if ((ret = create_meta(db, pack)) != MPORT_OK)
+ return ret;
+
+ if (sqlite3_close(db) != SQLITE_OK)
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+
+ if ((ret = tar_files(plist, pack)) != MPORT_OK)
+ return ret;
+
+ if ((ret = clean_up(tmpdir)) != MPORT_OK)
+ return ret;
+
+ return MPORT_OK;
+}
+
+
+static int create_package_db(sqlite3 **db)
+{
+ if (sqlite3_open(PACKAGE_DB_FILENAME, db) != 0) {
+ sqlite3_close(*db);
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(*db));
+ }
+
+ /* create tables */
+ mport_generate_package_schema(*db);
+
+ return MPORT_OK;
+}
+
+static int create_plist(sqlite3 *db, mportPlist *plist, mportPackageMeta *pack)
+{
+ mportPlistEntry *e;
+ sqlite3_stmt *stmnt;
+ const char *rest = 0;
+ int ret;
+ char sql[] = "INSERT INTO assets (pkg, type, data, checksum) VALUES (?,?,?,?)";
+ char md5[33];
+ char file[FILENAME_MAX];
+ char cwd[FILENAME_MAX];
+
+ strlcpy(cwd, pack->sourcedir, FILENAME_MAX);
+ strlcat(cwd, pack->prefix, FILENAME_MAX);
+
+ if (sqlite3_prepare_v2(db, sql, -1, &stmnt, &rest) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ STAILQ_FOREACH(e, plist, next) {
+ if (e->type == PLIST_CWD) {
+ strlcpy(cwd, pack->sourcedir, FILENAME_MAX);
+ if (e->data != NULL)
+ strlcat(cwd, e->data, FILENAME_MAX);
+ }
+
+ if (sqlite3_bind_text(stmnt, 1, pack->name, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ if (sqlite3_bind_int(stmnt, 2, e->type) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ if (sqlite3_bind_text(stmnt, 3, e->data, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ if (e->type == PLIST_FILE) {
+ snprintf(file, FILENAME_MAX, "%s/%s", cwd, e->data);
+
+ if (MD5File(file, md5) == NULL) {
+ char *error;
+ asprintf(&error, "File not found: %s", file);
+ RETURN_ERROR(MPORT_ERR_FILE_NOT_FOUND, error);
+ }
+
+ if (sqlite3_bind_text(stmnt, 4, md5, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ } else {
+ if (sqlite3_bind_null(stmnt, 4) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+ }
+ if ((ret = sqlite3_step(stmnt)) != SQLITE_DONE) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ sqlite3_reset(stmnt);
+ }
+
+ sqlite3_finalize(stmnt);
+
+ return MPORT_OK;
+}
+
+static int create_meta(sqlite3 *db, mportPackageMeta *pack)
+{
+ sqlite3_stmt *stmnt;
+ const char *rest = 0;
+ struct timespec now;
+
+ char sql[] = "INSERT INTO package (pkg, version, lang, date) VALUES (?,?,?,?)";
+
+ if (sqlite3_prepare_v2(db, sql, -1, &stmnt, &rest) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ if (sqlite3_bind_text(stmnt, 1, pack->name, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ if (sqlite3_bind_text(stmnt, 2, pack->version, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ if (sqlite3_bind_text(stmnt, 3, pack->lang, -1, SQLITE_STATIC) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ if (clock_gettime(CLOCK_REALTIME, &now) != 0) {
+ RETURN_ERROR(MPORT_ERR_SYSCALL_FAILED, strerror(errno));
+ }
+
+ if (sqlite3_bind_int(stmnt, 4, now.tv_sec) != SQLITE_OK) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ if (sqlite3_step(stmnt) != SQLITE_DONE) {
+ RETURN_ERROR(MPORT_ERR_SQLITE, sqlite3_errmsg(db));
+ }
+
+ sqlite3_finalize(stmnt);
+
+ return MPORT_OK;
+}
+
+static int tar_files(mportPlist *plist, mportPackageMeta *pack)
+{
+
+}
+
+static int clean_up(const char *tmpdir)
+{
+}
+
--- /dev/null
+++ lib/libmport/db_schema.c
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 2007 Chris Reinhardt
+ * 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.
+ *
+ * $MidnightBSD: src/lib/libmport/db_schema.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $
+ */
+
+
+
+#include <sqlite3.h>
+#include <stdlib.h>
+#include "mport.h"
+
+__MBSDID("$MidnightBSD: src/lib/libmport/db_schema.c,v 1.1 2007/09/23 22:30:52 ctriv Exp $");
+
+static void run_sql(sqlite3 *db, const char *sql);
+
+void mport_generate_package_schema(sqlite3 *db)
+{
+ run_sql(db, "CREATE TABLE assets (pkg text not NULL, type int NOT NULL, data text, checksum text)");
+ run_sql(db, "CREATE TABLE package (pkg text NOT NULL, version text NOT NULL, lang text, options text, date int NOT NULL)");
+ run_sql(db, "CREATE TABLE conflicts (pkg text NOT NULL, conflict text NOT NULL)");
+ run_sql(db, "CREATE TABLE depends (pkg text NOT NULL, depend text NOT NULL)");
+}
+
+static void run_sql(sqlite3 *db, const char *sql)
+{
+ char *error = 0;
+
+ sqlite3_exec(
+ db,
+ sql,
+ NULL,
+ NULL,
+ &error
+ );
+}
--- /dev/null
+++ lib/libmport/Makefile
@@ -0,0 +1,13 @@
+# $FreeBSD: src/usr.sbin/pkg_install/lib/Makefile,v 1.18 2004/10/24 15:33:07 ru Exp $
+
+LIB= mport
+SRCS= plist.c create_pkg.c db_schema.c util.c error.c
+
+WARNS?= 3
+WFORMAT?= 1
+SHLIB_MAJOR= 1
+
+DPADD= ${LIBSQLITE3} ${LIBMD}
+LDADD= -lsqlite3 -lmd
+
+.include <bsd.lib.mk>
More information about the Midnightbsd-cvs
mailing list