예제 #1
0
파일: pkgdb.c 프로젝트: flz/pkgng
int
pkgdb_loadoptions(struct pkgdb *db, struct pkg *pkg)
{
	sqlite3_stmt *stmt;
	struct pkg_option *o;
	int ret;
	const char sql[] = ""
		"SELECT option, value "
		"FROM options "
		"WHERE package_id = ?1";

	if (pkg->type != PKG_INSTALLED)
		return (ERROR_BAD_ARG("pkg"));

	if (pkg->flags & PKG_LOAD_OPTIONS)
		return (EPKG_OK);

	array_init(&pkg->options, 5);

	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
		return (ERROR_SQLITE(db->sqlite));

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

	while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
		pkg_option_new(&o);
		sbuf_set(&o->opt, sqlite3_column_text(stmt, 0));
		sbuf_set(&o->value, sqlite3_column_text(stmt, 1));
		array_append(&pkg->options, o);
	}
	sqlite3_finalize(stmt);

	if (ret != SQLITE_DONE) {
		array_reset(&pkg->options, &pkg_option_free_void);
		return (ERROR_SQLITE(db->sqlite));
	}

	pkg->flags |= PKG_LOAD_OPTIONS;
	return (EPKG_OK);
}
예제 #2
0
int main(int argc, char ** argv)
{
    if(argc >= 3)
    {   
        if(argc >= 4)
        {    
            g_dir = argv[3];
        }

        sbuf_set();
        event_init();
        start_server(argv[1], argv[2]);
        event_run_loop(5);
    }
    else
    {
        printf("%s ip port [dir]\n",argv[0]);
    } 

    return 0;
}
예제 #3
0
파일: pkgdb.c 프로젝트: flz/pkgng
int
pkgdb_loadscripts(struct pkgdb *db, struct pkg *pkg)
{
	sqlite3_stmt *stmt;
	struct pkg_script *s;
	int ret;
	const char sql[] = ""
		"SELECT script, type "
		"FROM scripts "
		"WHERE package_id = ?1";

	if (pkg->type != PKG_INSTALLED)
		return (ERROR_BAD_ARG("pkg"));

	if (pkg->flags & PKG_LOAD_SCRIPTS)
		return (EPKG_OK);

	array_init(&pkg->scripts, 6);

	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
		return (ERROR_SQLITE(db->sqlite));

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

	while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
		pkg_script_new(&s);
		sbuf_set(&s->data, sqlite3_column_text(stmt, 0));
		s->type = sqlite3_column_int(stmt, 1);
		array_append(&pkg->scripts, s);
	}
	sqlite3_finalize(stmt);

	if (ret != SQLITE_DONE) {
		array_reset(&pkg->scripts, &pkg_script_free_void);
		return (ERROR_SQLITE(db->sqlite));
	}

	pkg->flags |= PKG_LOAD_SCRIPTS;
	return (EPKG_OK);
}
예제 #4
0
파일: pkgdb.c 프로젝트: flz/pkgng
int
pkgdb_loadconflicts(struct pkgdb *db, struct pkg *pkg)
{
	sqlite3_stmt *stmt;
	struct pkg_conflict *c;
	int ret;
	const char sql[] = ""
		"SELECT name "
		"FROM conflicts "
		"WHERE package_id = ?1;";

	if (pkg->type != PKG_INSTALLED)
		return (ERROR_BAD_ARG("pkg"));

	if (pkg->flags & PKG_LOAD_CONFLICTS)
		return (EPKG_OK);

	array_init(&pkg->conflicts, 5);

	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
		return (ERROR_SQLITE(db->sqlite));

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

	while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
		pkg_conflict_new(&c);
		sbuf_set(&c->glob, sqlite3_column_text(stmt, 0));
		array_append(&pkg->conflicts, c);
	}
	sqlite3_finalize(stmt);

	if (ret != SQLITE_DONE) {
		array_reset(&pkg->conflicts, &pkg_conflict_free_void);
		return (ERROR_SQLITE(db->sqlite));
	}

	pkg->flags |= PKG_LOAD_CONFLICTS;

	return (EPKG_OK);
}
예제 #5
0
파일: pkgdb.c 프로젝트: flz/pkgng
int
pkgdb_loadmtree(struct pkgdb *db, struct pkg *pkg)
{
	sqlite3_stmt *stmt;
	int ret;
	const char sql[] = ""
		"SELECT m.content "
		"FROM mtree AS m, packages AS p "
		"WHERE m.id = p.mtree_id "
			" AND p.id = ?1;";

	if (pkg->type != PKG_INSTALLED)
		return (ERROR_BAD_ARG("pkg"));

	if (pkg->flags & PKG_LOAD_MTREE)
		return (EPKG_OK);

	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
		return (ERROR_SQLITE(db->sqlite));

	sqlite3_bind_int64(stmt, 1, pkg->rowid);

	ret = sqlite3_step(stmt);
	if (ret == SQLITE_ROW) {
		sbuf_set(&pkg->fields[PKG_MTREE].value,
				 sqlite3_column_text(stmt, 0));
		ret = SQLITE_DONE;
	}

	sqlite3_finalize(stmt);

	if (ret != SQLITE_DONE)
		return (ERROR_SQLITE(db->sqlite));

	pkg->flags |= PKG_LOAD_MTREE;
	return (EPKG_OK);
}