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 :=
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"
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);
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;
+}
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
/* --- 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);
}
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 $?