From: nishi Date: Sat, 11 May 2024 01:48:19 +0000 (+0000) Subject: list db X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=0971564e6c4e25afd344c048fecea8e8319f74cc;p=mandshurica.git list db git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@80 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/GNUmakefile b/GNUmakefile index 9376252..753d0db 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -4,9 +4,10 @@ MODULE_PREFIX := $(PREFIX)/lib/mandshurica/module WEBROOT_PREFIX := $(PREFIX)/lib/mandshurica/webroot PROJECTS_PREFIX := $(PREFIX)/lib/mandshurica/projects TOOL_PREFIX := $(PREFIX)/lib/mandshurica/tool +DATABASE_PREFIX := $(PREFIX)/lib/mandshurica/db CC := gcc -CFLAGS := -g -std=c99 -DPREFIX=\\\"$(PREFIX)\\\" -DWEBROOT_PREFIX=\\\"$(WEBROOT_PREFIX)\\\" -DMODULE_PREFIX=\\\"$(MODULE_PREFIX)\\\" -DPROJECTS_PREFIX=\\\"$(PROJECTS_PREFIX)\\\" -DTOOL_PREFIX=\\\"$(TOOL_PREFIX)\\\" -D_DEFAULT_SOURCE +CFLAGS := -g -std=c99 -DPREFIX=\\\"$(PREFIX)\\\" -DWEBROOT_PREFIX=\\\"$(WEBROOT_PREFIX)\\\" -DMODULE_PREFIX=\\\"$(MODULE_PREFIX)\\\" -DPROJECTS_PREFIX=\\\"$(PROJECTS_PREFIX)\\\" -DTOOL_PREFIX=\\\"$(TOOL_PREFIX)\\\" -DDATABASE_PREFIX=\\\"$(DATABASE_PREFIX)\\\" -D_DEFAULT_SOURCE LDFLAGS := LIBS := @@ -36,14 +37,14 @@ replace: done install: all - mkdir -p $(PREFIX) $(MODULE_PREFIX) $(WEBROOT_PREFIX) $(PROJECTS_PREFIX) $(TOOL_PREFIX) $(PREFIX)/etc $(PREFIX)/bin $(PREFIX)/lib/mandshurica/db + mkdir -p $(PREFIX) $(MODULE_PREFIX) $(DATABASE_PREFIX) $(WEBROOT_PREFIX) $(PROJECTS_PREFIX) $(TOOL_PREFIX) $(PREFIX)/etc $(PREFIX)/bin $(PREFIX)/lib/mandshurica/db touch $(PREFIX)/lib/mandshurica/db/auth.db $(PREFIX)/lib/mandshurica/db/login.db $(PREFIX)/lib/mandshurica/db/project.db cp ./mkpasswd.pl $(PREFIX)/bin/ ./Mandshurica/mandshurica --create $(PREFIX)/etc/mandshurica.conf $(MAKE) -C ./Mandshurica install PREFIX="$(PREFIX)" MODULE_PREFIX="$(MODULE_PREFIX)" PROJECTS_PREFIX="$(PROJECTS_PREFIX)" TOOL_PREFIX="$(TOOL_PREFIX)" WEBROOT_PREFIX="$(WEBROOT_PREFIX)" - $(MAKE) -C ./Module install PREFIX="$(PREFIX)" MODULE_PREFIX="$(MODULE_PREFIX)" PROJECTS_PREFIX="$(PROJECTS_PREFIX)" TOOL_PREFIX="$(TOOL_PREFIX)" WEBROOT_PREFIX="$(WEBROOT_PREFIX)" - $(MAKE) -C ./Tool install PREFIX="$(PREFIX)" MODULE_PREFIX="$(MODULE_PREFIX)" PROJECTS_PREFIX="$(PROJECTS_PREFIX)" TOOL_PREFIX="$(TOOL_PREFIX)" WEBROOT_PREFIX="$(WEBROOT_PREFIX)" - $(MAKE) -C ./Webroot install PREFIX="$(PREFIX)" MODULE_PREFIX="$(MODULE_PREFIX)" PROJECTS_PREFIX="$(PROJECTS_PREFIX)" TOOL_PREFIX="$(TOOL_PREFIX)" WEBROOT_PREFIX="$(WEBROOT_PREFIX)" + $(MAKE) -C ./Module install PREFIX="$(PREFIX)" MODULE_PREFIX="$(MODULE_PREFIX)" PROJECTS_PREFIX="$(PROJECTS_PREFIX)" TOOL_PREFIX="$(TOOL_PREFIX)" WEBROOT_PREFIX="$(WEBROOT_PREFIX)" DATABASE_PREFIX="$(DATABASE_PREFIX)" + $(MAKE) -C ./Tool install PREFIX="$(PREFIX)" MODULE_PREFIX="$(MODULE_PREFIX)" PROJECTS_PREFIX="$(PROJECTS_PREFIX)" TOOL_PREFIX="$(TOOL_PREFIX)" WEBROOT_PREFIX="$(WEBROOT_PREFIX)" DATABASE_PREFIX="$(DATABASE_PREFIX)" + $(MAKE) -C ./Webroot install PREFIX="$(PREFIX)" MODULE_PREFIX="$(MODULE_PREFIX)" PROJECTS_PREFIX="$(PROJECTS_PREFIX)" TOOL_PREFIX="$(TOOL_PREFIX)" WEBROOT_PREFIX="$(WEBROOT_PREFIX)" DATABASE_PREFIX="$(DATABASE_PREFIX)" @echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" @echo "Mandshurica executable has been installed to $(PREFIX)/bin" @echo "mkpasswd.pl has been installed to $(PREFIX)/bin" diff --git a/Mandshurica/config.c b/Mandshurica/config.c index bc4fc05..d54e48b 100644 --- a/Mandshurica/config.c +++ b/Mandshurica/config.c @@ -211,9 +211,9 @@ int mandshurica_create_config(const char* path) { fprintf(f, "# Generated by Mandshurica " MANDSHURICA_VERSION "\n"); fprintf(f, "ServerRoot %s\n", PREFIX); fprintf(f, "\n"); - fprintf(f, "Set AuthDB %s/lib/mandshurica/db/auth.db\n", PREFIX); - fprintf(f, "Set LoginDB %s/lib/mandshurica/db/login.db\n", PREFIX); - fprintf(f, "Set ProjectDB %s/lib/mandshurica/db/project.db\n", PREFIX); + fprintf(f, "Set AuthDB %s/auth.db\n", DATABASE_PREFIX); + fprintf(f, "Set LoginDB %s/login.db\n", DATABASE_PREFIX); + fprintf(f, "Set ProjectDB %s/project.db\n", DATABASE_PREFIX); fprintf(f, "Set HTTPPort 1024\n"); fprintf(f, "Set HTTPRoot %s\n", WEBROOT_PREFIX); fprintf(f, "Set HTMLManage %s/html-manage\n", TOOL_PREFIX); diff --git a/Mandshurica/db.c b/Mandshurica/db.c index 761371b..638171a 100644 --- a/Mandshurica/db.c +++ b/Mandshurica/db.c @@ -100,3 +100,49 @@ char* mandshurica_db_get(struct ms_db* db, const char* key) { funlockfile(db->fp); return NULL; } + +char** mandshurica_db_list(struct ms_db* db) { + flockfile(db->fp); + fseek(db->fp, 0, SEEK_SET); + char cbuf[2]; + cbuf[1] = 0; + char* line = malloc(1); + line[0] = 0; + char** list = malloc(sizeof(*list)); + list[0] = NULL; + while(1) { + fread(cbuf, 1, 1, db->fp); + if(feof(db->fp) || cbuf[0] == '\n') { + if(strlen(line) > 0) { + int i; + for(i = 0; line[i] != 0; i++) { + if(line[i] == ':') { + line[i] = 0; + char** old_list = list; + int j; + for(j = 0; old_list[j] != NULL; j++) + ; + list = malloc(sizeof(*list) * (j + 2)); + for(j = 0; old_list[j] != NULL; j++) list[j] = old_list[j]; + free(old_list); + list[j] = mandshurica_strdup(line); + list[j + 1] = NULL; + line[i] = 0; + break; + } + } + } + free(line); + line = malloc(1); + line[0] = 0; + if(feof(db->fp)) break; + } else if(cbuf[0] != '\r') { + char* tmp = line; + line = mandshurica_strcat(tmp, cbuf); + free(tmp); + } + } + free(line); + funlockfile(db->fp); + return list; +} diff --git a/Mandshurica/ms_db.h b/Mandshurica/ms_db.h index 3722cfc..fecb0a8 100644 --- a/Mandshurica/ms_db.h +++ b/Mandshurica/ms_db.h @@ -40,6 +40,7 @@ struct ms_db { struct ms_db* mandshurica_db_open(const char* path); void mandshurica_db_close(struct ms_db* db); char* mandshurica_db_get(struct ms_db* db, const char* key); +char** mandshurica_db_list(struct ms_db* db); void mandshurica_db_write(struct ms_db* db, const char* key, const char* value); #endif diff --git a/Tool/html-manage.c b/Tool/html-manage.c index b927d8d..df7d0fa 100644 --- a/Tool/html-manage.c +++ b/Tool/html-manage.c @@ -3,11 +3,22 @@ /* --- END LICENSE --- */ #include +#include + +#include "../Mandshurica/ms_db.h" int main(int argc, char** argv){ if(argc < 2){ fprintf(stderr, "invalid usage\n"); return 1; } - printf("%s\n", argv[1]); + struct ms_db* db = mandshurica_db_open(argv[1]); + char** keys = mandshurica_db_list(db); + int i; + for(i = 0; keys[i] != NULL; i++){ + printf("%s
\n", keys[i]); + free(keys[i]); + } + free(keys); + mandshurica_db_close(db); } diff --git a/build.sh b/build.sh index dfc2736..2d8f4d4 100755 --- a/build.sh +++ b/build.sh @@ -7,8 +7,8 @@ else MAKE=make fi if [ "`uname -s`" = "NetBSD" ]; then - $MAKE PREFIX=`pwd` MODULE_PREFIX=`pwd`/Module WEBROOT_PREFIX=`pwd`/Webroot PROJECTS_PREFIX=`pwd`/Projects TOOL_PREFIX=`pwd`/Tool -j`cat /proc/cpuinfo | grep proc | wc -l` + $MAKE PREFIX=`pwd` DATABASE_PREFIX=`pwd` MODULE_PREFIX=`pwd`/Module WEBROOT_PREFIX=`pwd`/Webroot PROJECTS_PREFIX=`pwd`/Projects TOOL_PREFIX=`pwd`/Tool -j`cat /proc/cpuinfo | grep proc | wc -l` else - $MAKE PREFIX=`pwd` MODULE_PREFIX=`pwd`/Module WEBROOT_PREFIX=`pwd`/Webroot PROJECTS_PREFIX=`pwd`/Projects TOOL_PREFIX=`pwd`/Tool -j`nproc` + $MAKE PREFIX=`pwd` DATABASE_PREFIX=`pwd` MODULE_PREFIX=`pwd`/Module WEBROOT_PREFIX=`pwd`/Webroot PROJECTS_PREFIX=`pwd`/Projects TOOL_PREFIX=`pwd`/Tool -j`nproc` fi exit $?