]> Nishi Git Mirror - mandshurica.git/commitdiff
list db
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 11 May 2024 01:48:19 +0000 (01:48 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 11 May 2024 01:48:19 +0000 (01:48 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@80 f982e544-4a7d-3444-ad1a-fde59a2a69f1

GNUmakefile
Mandshurica/config.c
Mandshurica/db.c
Mandshurica/ms_db.h
Tool/html-manage.c
build.sh

index 9376252a74ae84f207c0426417f3ad4c447a51bf..753d0db47248bb4ce0514be5dfe013567e8432c3 100644 (file)
@@ -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"
index bc4fc055428c4c4db34ee6d792dbe4134bc9429c..d54e48b4e4ec3c29ebfc745e71b0e2f81992d9f9 100644 (file)
@@ -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);
index 761371bf0e6d284a8c51160a8a9d4bd50f031004..638171a000fd59652ea44ce49a7f462c377b5a5f 100644 (file)
@@ -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;
+}
index 3722cfc7ed3cf97f4bef6778f3e920006687e228..fecb0a8f59755c9715adbed5b6ed8cc89db3a5ea 100644 (file)
@@ -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
index b927d8d86a1694912467be3cb20413e54b61cee2..df7d0fa49e0e145fdc0d036faa754fddb0ccf2d5 100644 (file)
@@ -3,11 +3,22 @@
 /* --- END LICENSE --- */
 
 #include <stdio.h>
+#include <stdlib.h>
+
+#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<br>\n", keys[i]);
+               free(keys[i]);
+       }
+       free(keys);
+       mandshurica_db_close(db);
 }
index dfc273636aeb4bc5a4eb0dd584354880b0913895..2d8f4d461fc80daf8a7be712e0355636dc3e9db9 100755 (executable)
--- 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 $?