From: nishi Date: Sun, 14 Apr 2024 02:51:00 +0000 (+0000) Subject: rename X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=f808776137e17da9d38434a65fa566c1e6ea8ce4;p=mandshurica.git rename git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@21 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/DevForge/util.c b/DevForge/util.c deleted file mode 100644 index 7bafa91..0000000 --- a/DevForge/util.c +++ /dev/null @@ -1,30 +0,0 @@ -/* $Id$ */ -/* --- START LICENESE --- */ -/* --- END LICENSE --- */ - -#include "df_util.h" - -#include -#include - -char* devforge_strcat(const char* str1, const char* str2) { - char* str = malloc(strlen(str1) + strlen(str2) + 1); - memcpy(str, str1, strlen(str1)); - memcpy(str + strlen(str1), str2, strlen(str2)); - str[strlen(str1) + strlen(str2)] = 0; - return str; -} - -char* devforge_strcat3(const char* str1, const char* str2, const char* str3) { - char* tmp = devforge_strcat(str1, str2); - char* r = devforge_strcat(tmp, str3); - free(tmp); - return r; -} - -char* devforge_strdup(const char* str) { - char* r = malloc(strlen(str) + 1); - memcpy(r, str, strlen(str)); - r[strlen(str)] = 0; - return r; -} diff --git a/HEADER b/HEADER index 54b866c..d62c294 100644 --- a/HEADER +++ b/HEADER @@ -1 +1 @@ -DevForge - Build Automation +Mandshurica - Build Automation diff --git a/Makefile b/Makefile index 0d91d2e..8b243a8 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,18 @@ # $Id$ PREFIX := /usr/local -MODULE_PREFIX := $(PREFIX)/lib/devforge -WEBROOT_PREFIX := $(PREFIX)/lib/devforge/webroot +MODULE_PREFIX := $(PREFIX)/lib/mandshurica +WEBROOT_PREFIX := $(PREFIX)/lib/mandshurica/webroot CC := gcc CFLAGS := -g -std=c99 -DPREFIX=\\\"$(PREFIX)\\\" -DWEBROOT_PREFIX=\\\"$(WEBROOT_PREFIX)\\\" -DMODULE_PREFIX=\\\"$(MODULE_PREFIX)\\\" -D_DEFAULT_SOURCE LDFLAGS := LIBS := -.PHONY: all clean format replace ./DevForge ./Module +.PHONY: all clean format replace ./Mandshurica ./Module -all: ./DevForge ./Module +all: ./Mandshurica ./Module -./DevForge:: +./Mandshurica:: $(MAKE) -C $@ CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" ./Module:: @@ -20,14 +20,14 @@ all: ./DevForge ./Module format: - clang-format -i $(wildcard Module/*.c Module/*.h DevForge/*.c DevForge/*.h) + clang-format -i $(wildcard Module/*.c Module/*.h Mandshurica/*.c Mandshurica/*.h) replace: - for i in $(wildcard Module/*.c Module/*.h DevForge/*.c DevForge/*.h); do \ + for i in $(wildcard Module/*.c Module/*.h Mandshurica/*.c Mandshurica/*.h); do \ cat $$i | perl replace.pl > $$i.new; \ mv $$i.new $$i; \ done clean: - $(MAKE) -C ./DevForge clean + $(MAKE) -C ./Mandshurica clean $(MAKE) -C ./Module clean diff --git a/DevForge/Makefile b/Mandshurica/Makefile similarity index 65% rename from DevForge/Makefile rename to Mandshurica/Makefile index 9ce892e..c3f4ebe 100644 --- a/DevForge/Makefile +++ b/Mandshurica/Makefile @@ -10,16 +10,16 @@ ifeq ($(shell uname -s),Linux) EXTRA_LIBS += -ldl endif -all: ./devforge +all: ./mandshurica -./devforge: ./main.o ./log.o ./config.o ./util.o +./mandshurica: ./main.o ./log.o ./config.o ./util.o $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LIBS) $(EXTRA_LIBS) -./main.o: ./main.c ./devforge.h +./main.o: ./main.c ./mandshurica.h $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< -./%.o: ./%.c ./df_%.h +./%.o: ./%.c ./mandshurica%.h $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< clean: - rm -f ./devforge ./*.o + rm -f ./mandshurica ./*.o diff --git a/DevForge/config.c b/Mandshurica/config.c similarity index 75% rename from DevForge/config.c rename to Mandshurica/config.c index a4559ff..4f6a24b 100644 --- a/DevForge/config.c +++ b/Mandshurica/config.c @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,12 +28,12 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#define DF_CONFIG_SRC -#include "df_config.h" +#define MS_CONFIG_SRC +#include "ms_config.h" -#include "devforge.h" -#include "df_log.h" -#include "df_util.h" +#include "mandshurica.h" +#include "ms_log.h" +#include "ms_util.h" #include #include @@ -43,8 +43,8 @@ #include #include -void devforge_add_mod(void* lib) { - struct devforge_mod** old_mods = loaded_mods; +void mandshurica_add_mod(void* lib) { + struct mandshurica_mod** old_mods = loaded_mods; int i; for(i = 0; old_mods[i] != NULL; i++) ; @@ -61,7 +61,7 @@ void devforge_add_mod(void* lib) { char** params = NULL; -void devforge_add_param(const char* key, const char* value) { +void mandshurica_add_param(const char* key, const char* value) { char** old_params = params; int i; for(i = 0; old_params[i] != NULL; i++) @@ -70,13 +70,13 @@ void devforge_add_param(const char* key, const char* value) { for(i = 0; old_params[i] != NULL; i++) { params[i] = old_params[i]; } - params[i] = devforge_strdup(key); - params[i + 1] = devforge_strdup(value); + params[i] = mandshurica_strdup(key); + params[i + 1] = mandshurica_strdup(value); params[i + 2] = NULL; free(old_params); } -char* devforge_get_param(const char* param) { +char* mandshurica_get_param(const char* param) { int i; for(i = 0; params[i] != NULL; i += 2) { if(strcmp(params[i], param) == 0) { @@ -86,11 +86,11 @@ char* devforge_get_param(const char* param) { return NULL; } -struct devforge_config config = {.devforge_log = devforge_log, .devforge_get_param = devforge_get_param}; +struct mandshurica_config config = {.mandshurica_log = mandshurica_log, .mandshurica_get_param = mandshurica_get_param}; -int devforge_load_config(const char* path) { +int mandshurica_load_config(const char* path) { if(server_root == NULL) { - server_root = devforge_strdup(PREFIX); + server_root = mandshurica_strdup(PREFIX); } if(loaded_mods == NULL) { @@ -103,8 +103,8 @@ int devforge_load_config(const char* path) { params[0] = NULL; } - char* str = devforge_strcat3("Loading the config `", path, "`"); - devforge_log(DF_LOG, str); + char* str = mandshurica_strcat3("Loading the config `", path, "`"); + mandshurica_log(MS_LOG, str); free(str); FILE* f = fopen(path, "r"); @@ -127,35 +127,35 @@ int devforge_load_config(const char* path) { char* value = str + i; if(strcmp(key, "ServerRoot") == 0) { free(server_root); - server_root = devforge_strdup(value); + server_root = mandshurica_strdup(value); } else if(strcmp(key, "Set") == 0) { for(; value[i] != 0 && !(value[i] == ' ' || value[i] == '\t'); i++) ; if(value[i] != 0) { for(; value[i] != 0 && (value[i] == ' ' || value[i] == '\t'); i++) value[i] = 0; if(value[i] != 0) { - devforge_add_param(value, value + i); + mandshurica_add_param(value, value + i); } } } else if(strcmp(key, "LoadModule") == 0) { char* path; if(value[0] == '/') { - path = devforge_strdup(value); + path = mandshurica_strdup(value); } else { - path = devforge_strcat3(server_root, "/", value); + path = mandshurica_strcat3(server_root, "/", value); } void* lib = dlopen(path, RTLD_LAZY); if(lib != NULL) { - int (*init_func)(struct devforge_config*) = (int (*)(struct devforge_config*))dlsym(lib, "mod_init"); + int (*init_func)(struct mandshurica_config*) = (int (*)(struct mandshurica_config*))dlsym(lib, "mod_init"); int ret = 0; if(init_func != NULL) { ret = init_func(&config); } if(ret == 0) { - devforge_add_mod(lib); + mandshurica_add_mod(lib); } else { - char* str = devforge_strcat3("Could not load the module `", path, "`"); - devforge_log(DF_ERROR, str); + char* str = mandshurica_strcat3("Could not load the module `", path, "`"); + mandshurica_log(MS_ERROR, str); free(str); dlclose(lib); } @@ -172,36 +172,36 @@ int devforge_load_config(const char* path) { if(feof(f)) break; } else { char* tmp = str; - str = devforge_strcat(tmp, cbuf); + str = mandshurica_strcat(tmp, cbuf); free(tmp); } } free(str); fclose(f); } else { - devforge_log(DF_ERROR, strerror(errno)); + mandshurica_log(MS_ERROR, strerror(errno)); return 1; } return 0; } -int devforge_create_config(const char* path) { - char* str = devforge_strcat3("Creating the config `", path, "`"); - devforge_log(DF_LOG, str); +int mandshurica_create_config(const char* path) { + char* str = mandshurica_strcat3("Creating the config `", path, "`"); + mandshurica_log(MS_LOG, str); free(str); FILE* f = fopen(path, "w"); if(f != NULL) { - fprintf(f, "# Generated by DevForge " DEVFORGE_VERSION "\n"); + fprintf(f, "# Generated by Mandshurica " MANDSHURICA_VERSION "\n"); fprintf(f, "ServerRoot %s\n", PREFIX); fprintf(f, "LoadModule %s/http.so\n", MODULE_PREFIX); fprintf(f, "LoadModule %s/subversion.so\n", MODULE_PREFIX); fprintf(f, "LoadModule %s/syslog.so\n", MODULE_PREFIX); fclose(f); - devforge_log(DF_LOG, "Created the config"); + mandshurica_log(MS_LOG, "Created the config"); } else { - devforge_log(DF_ERROR, strerror(errno)); + mandshurica_log(MS_ERROR, strerror(errno)); return 1; } diff --git a/DevForge/log.c b/Mandshurica/log.c similarity index 91% rename from DevForge/log.c rename to Mandshurica/log.c index e62b120..cf80584 100644 --- a/DevForge/log.c +++ b/Mandshurica/log.c @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,10 +28,10 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#include "df_log.h" +#include "ms_log.h" -#include "devforge.h" -#include "df_config.h" +#include "mandshurica.h" +#include "ms_config.h" #include #include @@ -39,13 +39,13 @@ #include #include -void devforge_log(const char* name, const char* log) { +void mandshurica_log(const char* name, const char* log) { bool fallback = true; if(loaded_mods != NULL) { int i; for(i = 0; loaded_mods[i] != NULL; i++) { const char* type = (const char*)dlsym(loaded_mods[i]->lib, "mod_type"); - if(strcmp(type, DF_MOD_LOG) == 0) { + if(strcmp(type, MS_MOD_LOG) == 0) { void (*mod_log)(const char*, const char*) = (void (*)(const char*, const char*))dlsym(loaded_mods[i]->lib, "mod_log"); if(mod_log != NULL) { fallback = false; diff --git a/DevForge/main.c b/Mandshurica/main.c similarity index 84% rename from DevForge/main.c rename to Mandshurica/main.c index 40c3546..9b215d6 100644 --- a/DevForge/main.c +++ b/Mandshurica/main.c @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,10 +28,10 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#include "devforge.h" +#include "mandshurica.h" -#include "df_config.h" -#include "df_log.h" +#include "ms_config.h" +#include "ms_log.h" #include #include @@ -39,12 +39,12 @@ #include #include -extern struct devforge_config config; +extern struct mandshurica_config config; int main(int argc, char** argv) { int i; bool loaded_config = false; - devforge_log(DF_INFO, "DevForge " DEVFORGE_VERSION " Copyright (C) 2024 Nishi"); + mandshurica_log(MS_INFO, "Mandshurica " MANDSHURICA_VERSION " Copyright (C) 2024 Nishi"); for(i = 1; i < argc; i++) { if(argv[i][0] == '-') { if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) { @@ -53,7 +53,7 @@ int main(int argc, char** argv) { fprintf(stderr, "%s: %s: needs argument\n", argv[0], argv[i - 1]); return 1; } else { - int ret = devforge_load_config(argv[i]); + int ret = mandshurica_load_config(argv[i]); if(ret != 0) return ret; loaded_config = true; } @@ -63,7 +63,7 @@ int main(int argc, char** argv) { fprintf(stderr, "%s: %s: needs argument\n", argv[0], argv[i - 1]); return 1; } else { - return devforge_create_config(argv[i]); + return mandshurica_create_config(argv[i]); } } else { fprintf(stderr, "%s: %s: unknown option\n", argv[0], argv[i]); @@ -72,18 +72,18 @@ int main(int argc, char** argv) { } } if(!loaded_config) { - int ret = devforge_load_config(PREFIX "/etc/devforge.conf"); + int ret = mandshurica_load_config(PREFIX "/etc/mandshurica.conf"); if(ret != 0) return ret; } - devforge_log(DF_INFO, "Hello World, initialization done"); + mandshurica_log(MS_INFO, "Hello World, initialization done"); if(loaded_mods != NULL) { - devforge_log(DF_INFO, "Starting server"); + mandshurica_log(MS_INFO, "Starting server"); int i; bool loaded_srv = false; for(i = 0; loaded_mods[i] != NULL; i++) { const char* type = (const char*)dlsym(loaded_mods[i]->lib, "mod_type"); if(type != NULL) { - if(strcmp(type, DF_MOD_SRV) == 0) { + if(strcmp(type, MS_MOD_SRV) == 0) { void* (*mod_server_thread)(void*) = (void* (*)(void*))dlsym(loaded_mods[i]->lib, "mod_server_thread"); if(mod_server_thread != NULL) { pthread_create(&loaded_mods[i]->thread, NULL, mod_server_thread, &config); @@ -107,5 +107,5 @@ int main(int argc, char** argv) { return ret; } } - devforge_log(DF_ERROR, "Server module was not loaded!"); + mandshurica_log(MS_ERROR, "Server module was not loaded!"); } diff --git a/DevForge/devforge.h b/Mandshurica/mandshurica.h similarity index 83% rename from DevForge/devforge.h rename to Mandshurica/mandshurica.h index 329d21b..820971a 100644 --- a/DevForge/devforge.h +++ b/Mandshurica/mandshurica.h @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,18 +28,18 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#ifndef __DEVFORGE_DEVFORGE_H__ -#define __DEVFORGE_DEVFORGE_H__ +#ifndef __MANDSHURICA_MANDSHURICA_H__ +#define __MANDSHURICA_MANDSHURICA_H__ -#define DEVFORGE_VERSION "0.0" +#define MANDSHURICA_VERSION "0.0" -#define DF_MOD_LOG "LOG" -#define DF_MOD_VCS "VCS" -#define DF_MOD_SRV "SRV" +#define MS_MOD_LOG "LOG" +#define MS_MOD_VCS "VCS" +#define MS_MOD_SRV "SRV" -struct devforge_config { - void (*devforge_log)(const char*, const char*); - char* (*devforge_get_param)(const char* param); +struct mandshurica_config { + void (*mandshurica_log)(const char*, const char*); + char* (*mandshurica_get_param)(const char* param); }; #endif diff --git a/DevForge/df_config.h b/Mandshurica/ms_config.h similarity index 82% rename from DevForge/df_config.h rename to Mandshurica/ms_config.h index 2e11ff5..ddc9e5f 100644 --- a/DevForge/df_config.h +++ b/Mandshurica/ms_config.h @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,36 +28,36 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#ifndef __DEVFORGE_DF_CONFIG_H__ -#define __DEVFORGE_DF_CONFIG_H__ +#ifndef __MANDSHURICA_MS_CONFIG_H__ +#define __MANDSHURICA_MS_CONFIG_H__ #include #include #include -int devforge_load_config(const char* path); -int devforge_create_config(const char* path); +int mandshurica_load_config(const char* path); +int mandshurica_create_config(const char* path); -struct devforge_mod { +struct mandshurica_mod { void* lib; pthread_t thread; bool joinable; }; -#ifdef DF_CONFIG_SRC -#define DF_CONFIG_PREFIX +#ifdef MS_CONFIG_SRC +#define MS_CONFIG_PREFIX #else -#define DF_CONFIG_PREFIX extern +#define MS_CONFIG_PREFIX extern #endif -DF_CONFIG_PREFIX char* server_root -#ifdef DF_CONFIG_SRC +MS_CONFIG_PREFIX char* server_root +#ifdef MS_CONFIG_SRC = NULL #endif ; -DF_CONFIG_PREFIX struct devforge_mod** loaded_mods -#ifdef DF_CONFIG_SRC +MS_CONFIG_PREFIX struct mandshurica_mod** loaded_mods +#ifdef MS_CONFIG_SRC = NULL #endif ; diff --git a/DevForge/df_log.h b/Mandshurica/ms_log.h similarity index 87% rename from DevForge/df_log.h rename to Mandshurica/ms_log.h index 0ff4f99..7de8aa8 100644 --- a/DevForge/df_log.h +++ b/Mandshurica/ms_log.h @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,14 +28,14 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#ifndef __DEVFORGE_DF_LOG_H__ -#define __DEVFORGE_DF_LOG_H__ +#ifndef __MANDSHURICA_MS_LOG_H__ +#define __MANDSHURICA_MS_LOG_H__ -#define DF_WARN "WARNING" -#define DF_ERROR "ERROR" -#define DF_INFO "INFO" -#define DF_LOG "LOG" +#define MS_WARN "WARNING" +#define MS_ERROR "ERROR" +#define MS_INFO "INFO" +#define MS_LOG "LOG" -void devforge_log(const char* name, const char* log); +void mandshurica_log(const char* name, const char* log); #endif diff --git a/DevForge/df_util.h b/Mandshurica/ms_util.h similarity index 81% rename from DevForge/df_util.h rename to Mandshurica/ms_util.h index 136469b..2178e72 100644 --- a/DevForge/df_util.h +++ b/Mandshurica/ms_util.h @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,11 +28,15 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#ifndef __DEVFORGE_DF_UTIL_H__ -#define __DEVFORGE_DF_UTIL_H__ +#ifndef __MANDSHURICA_MS_UTIL_H__ +#define __MANDSHURICA_MS_UTIL_H__ -char* devforge_strcat(const char* str1, const char* str2); -char* devforge_strcat3(const char* str1, const char* str2, const char* str3); -char* devforge_strdup(const char* str); +#include + +char* mandshurica_strcat(const char* str1, const char* str2); +char* mandshurica_strcat3(const char* str1, const char* str2, const char* str3); +char* mandshurica_strdup(const char* str); +bool mandshurica_strequ(const char* str1, const char* str2); +bool mandshurica_strcaseequ(const char* str1, const char* str2); #endif diff --git a/Mandshurica/util.c b/Mandshurica/util.c new file mode 100644 index 0000000..41f2720 --- /dev/null +++ b/Mandshurica/util.c @@ -0,0 +1,76 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Mandshurica - Build Automation */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Nishi. */ +/* Redistribution and use in source and binary forms, with or without modific */ +/* ation, are permitted provided that the following conditions are met: */ +/* 1. Redistributions of source code must retain the above copyright noti */ +/* ce, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright n */ +/* otice, this list of conditions and the following disclaimer in the documen */ +/* tation and/or other materials provided with the distribution. */ +/* 3. Neither the name of the copyright holder nor the names of its contr */ +/* ibutors may be used to endorse or promote products derived from this softw */ +/* are without specific prior written permission. */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */ +/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */ +/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */ +/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */ +/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */ +/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */ +/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */ +/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */ +/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */ +/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */ +/* OF SUCH DAMAGE. */ +/* -------------------------------------------------------------------------- */ +/* --- END LICENSE --- */ + +#include "ms_util.h" + +#include +#include +#include +#include + +char* mandshurica_strcat(const char* str1, const char* str2) { + char* str = malloc(strlen(str1) + strlen(str2) + 1); + memcpy(str, str1, strlen(str1)); + memcpy(str + strlen(str1), str2, strlen(str2)); + str[strlen(str1) + strlen(str2)] = 0; + return str; +} + +char* mandshurica_strcat3(const char* str1, const char* str2, const char* str3) { + char* tmp = mandshurica_strcat(str1, str2); + char* r = mandshurica_strcat(tmp, str3); + free(tmp); + return r; +} + +char* mandshurica_strdup(const char* str) { + char* r = malloc(strlen(str) + 1); + memcpy(r, str, strlen(str)); + r[strlen(str)] = 0; + return r; +} + +bool mandshurica_strequ(const char* str1, const char* str2) { + if(strlen(str1) != strlen(str2)) return false; + int i; + for(i = 0; str1[i] != 0; i++){ + if(str1[i] != str2[i]) return false; + } + return true; +} + +bool mandshurica_strcaseequ(const char* str1, const char* str2) { + if(strlen(str1) != strlen(str2)) return false; + int i; + for(i = 0; str1[i] != 0; i++){ + if(tolower(str1[i]) != tolower(str2[i])) return false; + } + return true; +} diff --git a/Module/Makefile b/Module/Makefile index 84a1a21..c538330 100644 --- a/Module/Makefile +++ b/Module/Makefile @@ -11,10 +11,10 @@ all: ./subversion.so ./syslog.so ./http.so ./%.so: ./%.o ./util.o $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LIBS) $(EXTRA_LIBS) -./util.o: ../DevForge/util.c +./util.o: ../Mandshurica/util.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< -./%.o: ./%.c ../DevForge/devforge.h +./%.o: ./%.c ../Mandshurica/mandshurica.h $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< clean: diff --git a/Module/http.c b/Module/http.c index e13052b..7f05ff8 100644 --- a/Module/http.c +++ b/Module/http.c @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,33 +28,33 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#include "../DevForge/devforge.h" -#include "../DevForge/df_log.h" -#include "../DevForge/df_util.h" +#include "../Mandshurica/mandshurica.h" +#include "../Mandshurica/ms_log.h" +#include "../Mandshurica/ms_util.h" +#include +#include #include #include -#include #include -#include -#include #include +#include -#include -#include #include +#include +#include -const char mod_type[] = DF_MOD_SRV; +const char mod_type[] = MS_MOD_SRV; -struct devforge_config* config; +struct mandshurica_config* config; -int mod_init(struct devforge_config* _config) { +int mod_init(struct mandshurica_config* _config) { config = _config; - config->devforge_log(DF_INFO, "HTTP Module init"); - char* port = config->devforge_get_param("HTTPPort"); + config->mandshurica_log(MS_INFO, "HTTP Module init"); + char* port = config->mandshurica_get_param("HTTPPort"); if(port == NULL) port = "1024"; - char* log = devforge_strcat("HTTP Server will listen on port ", port); - config->devforge_log(DF_INFO, log); + char* log = mandshurica_strcat("HTTP Server will listen on port ", port); + config->mandshurica_log(MS_INFO, log); free(log); return 0; } @@ -65,104 +65,167 @@ void http_handler(int sock) { char* buf = malloc(BUFFER_SIZE); char* method = NULL; char* path = NULL; + char* header = NULL; + char** headers = NULL; char cbuf[2]; cbuf[1] = 0; - while(true){ + while(true) { int state; int count; -reset:; + reset:; state = 0; count = 0; - if(method != NULL){ + if(method != NULL) { free(method); + method = NULL; } - if(path != NULL){ + if(path != NULL) { free(path); + path = NULL; } - while(true){ + if(header != NULL) { + free(header); + header = NULL; + } + if(headers != NULL) { + int i; + for(i = 0; headers[i] != NULL; i++) free(headers[i]); + free(headers); + headers = NULL; + } + while(true) { int len = recv(sock, buf, BUFFER_SIZE, 0); if(len <= 0) goto goquit; int i; - for(i = 0; i < len; i++){ + for(i = 0; i < len; i++) { cbuf[0] = buf[i]; - if(state == 0){ - if(buf[i] == ' '){ + if(state == 0) { + if(buf[i] == ' ') { state = 1; - }else{ + } else { char* tmp = method; - method = devforge_strcat(tmp == NULL ? "" : tmp, cbuf); + method = mandshurica_strcat(tmp == NULL ? "" : tmp, cbuf); if(tmp != NULL) free(tmp); } - }else if(state == 1){ - if(buf[i] == ' '){ + } else if(state == 1) { + if(buf[i] == ' ') { state = 2; - }else{ + } else { char* tmp = path; - path = devforge_strcat(tmp == NULL ? "" : tmp, cbuf); + path = mandshurica_strcat(tmp == NULL ? "" : tmp, cbuf); if(tmp != NULL) free(tmp); } - }else if(state == 2){ - if(buf[i] == '\r'){ - }else if(buf[i] == '\n'){ + } else if(state == 2) { + if(buf[i] == '\r') { + } else if(buf[i] == '\n') { state = 3; } - }else if(state == 3){ - if(buf[i] == '\r'){ - }else if(buf[i] == '\n'){ + } else if(state == 3) { + if(buf[i] == '\r') { + } else if(buf[i] == '\n') { count++; - if(count == 2){ - if(strcmp(method, "GET") == 0){ + if(count == 2) { + if(strcmp(method, "GET") == 0) { goto reset; } state = 0; + } else { + if(header != NULL) { + int j; + for(j = 0; header[j] != 0; j++) { + if(header[j] == ':') { + header[j] = 0; + j++; + for(; header[j] != 0 && (header[j] == ' ' || header[j] == '\t'); j++) + ; + if(header[j] != 0) { + char* key = header; + char* value = header + j; + if(headers == NULL){ + headers = malloc(sizeof(*headers)); + headers[0] = NULL; + } + char** old_headers = headers; + int k; + for(k = 0; headers[k] != NULL; k++); + headers = malloc(sizeof(*headers) * (k + 3)); + for(k = 0; old_headers[k] != NULL; k++){ + headers[k] = old_headers[k]; + } + headers[k] = mandshurica_strdup(key); + headers[k + 1] = mandshurica_strdup(value); + headers[k + 2] = NULL; + free(old_headers); + } + break; + } + } + } + if(header != NULL) free(header); + header = NULL; } - }else{ + } else { count = 0; + char* tmp = header; + header = mandshurica_strcat(tmp == NULL ? "" : tmp, cbuf); + if(tmp != NULL) free(tmp); } } } } } goquit:; + if(method != NULL) { + free(method); + method = NULL; + } + if(path != NULL) { + free(path); + path = NULL; + } + if(header != NULL) { + free(header); + header = NULL; + } free(buf); } void* mod_server_thread(void* ptr) { int* ret = malloc(sizeof(*ret)); *ret = 0; - struct devforge_config* sconfig = (struct devforge_config*)ptr; - sconfig->devforge_log(DF_INFO, "HTTP server preparing"); + struct mandshurica_config* sconfig = (struct mandshurica_config*)ptr; + sconfig->mandshurica_log(MS_INFO, "HTTP server preparing"); int server_socket; struct sockaddr_in6 server_address; - + int yes = 1; int no = 0; - if((server_socket = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0){ + if((server_socket = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0) { *ret = 1; return (void*)ret; } - if(setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0){ + if(setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { close(server_socket); - sconfig->devforge_log(DF_ERROR, "setsockopt(SOL_SOCKET, SO_REUSEADDR) failed"); + sconfig->mandshurica_log(MS_ERROR, "setsockopt(SOL_SOCKET, SO_REUSEADDR) failed"); *ret = 1; return (void*)ret; } - if(setsockopt(server_socket, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) < 0){ + if(setsockopt(server_socket, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) < 0) { close(server_socket); - sconfig->devforge_log(DF_ERROR, "setsockopt(IPPROTO_TCP, TCP_NODELAY) failed"); + sconfig->mandshurica_log(MS_ERROR, "setsockopt(IPPROTO_TCP, TCP_NODELAY) failed"); *ret = 1; return (void*)ret; } - if(setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof(no)) < 0){ + if(setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof(no)) < 0) { close(server_socket); - sconfig->devforge_log(DF_ERROR, "setsockopt(IPPROTO_IPV6, IPV6_V6ONLY) failed"); + sconfig->mandshurica_log(MS_ERROR, "setsockopt(IPPROTO_IPV6, IPV6_V6ONLY) failed"); *ret = 1; return (void*)ret; } - char* port = config->devforge_get_param("HTTPPort"); + char* port = config->mandshurica_get_param("HTTPPort"); if(port == NULL) port = "1024"; memset(&server_address, 0, sizeof(server_address)); @@ -170,31 +233,31 @@ void* mod_server_thread(void* ptr) { server_address.sin6_addr = in6addr_any; server_address.sin6_port = htons(atoi(port)); - if(bind(server_socket, (struct sockaddr*)&server_address, sizeof(server_address)) < 0){ + if(bind(server_socket, (struct sockaddr*)&server_address, sizeof(server_address)) < 0) { close(server_socket); - sconfig->devforge_log(DF_ERROR, "bind() failed"); + sconfig->mandshurica_log(MS_ERROR, "bind() failed"); *ret = 1; return (void*)ret; } - if(listen(server_socket, 128) < 0){ + if(listen(server_socket, 128) < 0) { close(server_socket); - sconfig->devforge_log(DF_ERROR, "listen() failed"); + sconfig->mandshurica_log(MS_ERROR, "listen() failed"); *ret = 1; return (void*)ret; } signal(SIGCHLD, SIG_IGN); - sconfig->devforge_log(DF_INFO, "HTTP server ready"); + sconfig->mandshurica_log(MS_INFO, "HTTP server ready"); - while(1){ + while(1) { struct sockaddr_storage claddr; int clen = sizeof(claddr); int sock = accept(server_socket, (struct sockaddr*)&claddr, &clen); pid_t pid = fork(); - if(pid == 0){ + if(pid == 0) { http_handler(sock); _exit(0); - }else{ + } else { close(sock); } } diff --git a/Module/subversion.c b/Module/subversion.c index 7767f06..6796739 100644 --- a/Module/subversion.c +++ b/Module/subversion.c @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,30 +28,30 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#include "../DevForge/devforge.h" -#include "../DevForge/df_log.h" -#include "../DevForge/df_util.h" +#include "../Mandshurica/mandshurica.h" +#include "../Mandshurica/ms_log.h" +#include "../Mandshurica/ms_util.h" #include #include #include #include -const char mod_type[] = DF_MOD_VCS; +const char mod_type[] = MS_MOD_VCS; -struct devforge_config* config; +struct mandshurica_config* config; char* svn_exec = NULL; -int mod_init(struct devforge_config* _config) { +int mod_init(struct mandshurica_config* _config) { config = _config; - config->devforge_log(DF_INFO, "Subversion Module init"); + config->mandshurica_log(MS_INFO, "Subversion Module init"); char* path = getenv("PATH"); if(path == NULL) { - config->devforge_log(DF_ERROR, "PATH is not set!"); + config->mandshurica_log(MS_ERROR, "PATH is not set!"); return 1; } else { - char* envpath = devforge_strdup(path); + char* envpath = mandshurica_strdup(path); int i; int start = 0; for(i = 0;; i++) { @@ -60,10 +60,10 @@ int mod_init(struct devforge_config* _config) { envpath[i] = 0; if(strlen(envpath + start) > 0) { - char* exec = devforge_strcat(envpath + start, "/svn"); + char* exec = mandshurica_strcat(envpath + start, "/svn"); if(access(exec, X_OK) == 0) { - char* found = devforge_strcat3("Found the Subversion executable `", exec, "`"); - config->devforge_log(DF_INFO, found); + char* found = mandshurica_strcat3("Found the Subversion executable `", exec, "`"); + config->mandshurica_log(MS_INFO, found); free(found); svn_exec = exec; break; @@ -76,7 +76,7 @@ int mod_init(struct devforge_config* _config) { } } if(svn_exec == NULL) { - config->devforge_log(DF_ERROR, "Could not find the Subversion executable!"); + config->mandshurica_log(MS_ERROR, "Could not find the Subversion executable!"); free(envpath); return 1; } diff --git a/Module/syslog.c b/Module/syslog.c index 29a780d..c87de5c 100644 --- a/Module/syslog.c +++ b/Module/syslog.c @@ -1,7 +1,7 @@ /* $Id$ */ /* --- START LICENSE --- */ /* -------------------------------------------------------------------------- */ -/* DevForge - Build Automation */ +/* Mandshurica - Build Automation */ /* -------------------------------------------------------------------------- */ /* Copyright (c) 2024 Nishi. */ /* Redistribution and use in source and binary forms, with or without modific */ @@ -28,30 +28,30 @@ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ -#include "../DevForge/devforge.h" -#include "../DevForge/df_log.h" +#include "../Mandshurica/mandshurica.h" +#include "../Mandshurica/ms_log.h" #include #include -const char mod_type[] = DF_MOD_LOG; +const char mod_type[] = MS_MOD_LOG; -struct devforge_config* config; +struct mandshurica_config* config; -int mod_init(struct devforge_config* _config) { +int mod_init(struct mandshurica_config* _config) { config = _config; - config->devforge_log(DF_INFO, "Syslog Module init"); + config->mandshurica_log(MS_INFO, "Syslog Module init"); return 0; } void mod_log(const char* name, const char* log) { - if(strcmp(name, DF_INFO) == 0) { + if(strcmp(name, MS_INFO) == 0) { syslog(LOG_INFO, log); - } else if(strcmp(name, DF_LOG) == 0) { + } else if(strcmp(name, MS_LOG) == 0) { syslog(LOG_NOTICE, log); - } else if(strcmp(name, DF_ERROR) == 0) { + } else if(strcmp(name, MS_ERROR) == 0) { syslog(LOG_ERR, log); - } else if(strcmp(name, DF_WARN) == 0) { + } else if(strcmp(name, MS_WARN) == 0) { syslog(LOG_WARNING, log); } }