From: nishi Date: Sat, 13 Apr 2024 02:19:02 +0000 (+0000) Subject: works X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=0f32c57489b1db6607dc6cd9957a16a51f9a06e7;p=mandshurica.git works git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@9 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/DevForge/config.c b/DevForge/config.c index 5d843eb..bf20ce7 100644 --- a/DevForge/config.c +++ b/DevForge/config.c @@ -42,12 +42,13 @@ #include #include -void devforge_add_mod(void* lib){ +void devforge_add_mod(void* lib) { void** old_mods = loaded_mods; int i; - for(i = 0; old_mods[i] != NULL; i++); + for(i = 0; old_mods[i] != NULL; i++) + ; loaded_mods = malloc(sizeof(*loaded_mods) * (i + 2)); - for(i = 0; old_mods[i] != NULL; i++){ + for(i = 0; old_mods[i] != NULL; i++) { loaded_mods[i] = old_mods[i]; } loaded_mods[i] = lib; @@ -56,11 +57,11 @@ void devforge_add_mod(void* lib){ } int devforge_load_config(const char* path) { - if(server_root == NULL){ + if(server_root == NULL) { server_root = devforge_strdup(PREFIX); } - if(loaded_mods == NULL){ + if(loaded_mods == NULL) { loaded_mods = malloc(sizeof(*loaded_mods)); loaded_mods[0] = NULL; } @@ -82,24 +83,24 @@ int devforge_load_config(const char* path) { } else if(str[0] == '#') { } else { int i; - for(i = 0; str[i] != 0; i++){ - if(str[i] == ' ' || str[i] == '\t'){ + for(i = 0; str[i] != 0; i++) { + if(str[i] == ' ' || str[i] == '\t') { for(; str[i] != 0 && (str[i] == ' ' || str[i] == '\t'); i++) str[i] = 0; char* key = str; char* value = str + i; - if(strcmp(key, "ServerRoot") == 0){ + if(strcmp(key, "ServerRoot") == 0) { free(server_root); server_root = devforge_strdup(value); - }else if(strcmp(key, "LoadModule") == 0){ + } else if(strcmp(key, "LoadModule") == 0) { char* path; - if(value[0] == '/'){ + if(value[0] == '/') { path = devforge_strdup(value); - }else{ + } else { path = devforge_strcat3(server_root, "/", value); } void* lib = dlopen(path, RTLD_LAZY); - if(lib != NULL){ - void(*init_func)(void(*)(const char*, const char*)) = (void(*)(void(*)(const char*, const char*)))dlsym(lib, "mod_init"); + if(lib != NULL) { + void (*init_func)(void (*)(const char*, const char*)) = (void (*)(void (*)(const char*, const char*)))dlsym(lib, "mod_init"); if(init_func != NULL) init_func(devforge_log); devforge_add_mod(lib); } @@ -137,6 +138,7 @@ int devforge_create_config(const char* path) { if(f != NULL) { fprintf(f, "# Generated by DevForge " DEVFORGE_VERSION "\n"); fprintf(f, "ServerRoot %s\n", 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"); diff --git a/DevForge/devforge.h b/DevForge/devforge.h index 72a91a5..8f7e734 100644 --- a/DevForge/devforge.h +++ b/DevForge/devforge.h @@ -34,5 +34,6 @@ #define DEVFORGE_VERSION "0.0" #define DF_MOD_LOG "LOG" +#define DF_MOD_VCS "VCS" #endif diff --git a/DevForge/df_config.h b/DevForge/df_config.h index aab73ee..c48ef9f 100644 --- a/DevForge/df_config.h +++ b/DevForge/df_config.h @@ -44,14 +44,14 @@ int devforge_create_config(const char* path); DF_CONFIG_PREFIX char* server_root #ifdef DF_CONFIG_SRC - = NULL + = NULL #endif -; + ; DF_CONFIG_PREFIX void** loaded_mods #ifdef DF_CONFIG_SRC - = NULL + = NULL #endif -; + ; #endif diff --git a/DevForge/log.c b/DevForge/log.c index 288d03b..62a739e 100644 --- a/DevForge/log.c +++ b/DevForge/log.c @@ -30,24 +30,24 @@ #include "df_log.h" -#include "df_config.h" #include "devforge.h" +#include "df_config.h" -#include -#include -#include #include +#include +#include #include +#include void devforge_log(const char* name, const char* log) { bool fallback = true; - if(loaded_mods != NULL){ + if(loaded_mods != NULL) { int i; - for(i = 0; loaded_mods[i] != NULL; i++){ + for(i = 0; loaded_mods[i] != NULL; i++) { const char* type = (const char*)dlsym(loaded_mods[i], "mod_type"); - if(strcmp(type, DF_MOD_LOG) == 0){ - void(*mod_log)(const char*, const char*) = (void(*)(const char*, const char*))dlsym(loaded_mods[i], "mod_log"); - if(mod_log != NULL){ + if(strcmp(type, DF_MOD_LOG) == 0) { + void (*mod_log)(const char*, const char*) = (void (*)(const char*, const char*))dlsym(loaded_mods[i], "mod_log"); + if(mod_log != NULL) { fallback = false; mod_log(name, log); break; @@ -56,7 +56,7 @@ void devforge_log(const char* name, const char* log) { } } - if(fallback){ + if(fallback) { char timestr[256]; time_t t = time(NULL); struct tm* tm = localtime(&t); diff --git a/DevForge/util.c b/DevForge/util.c index 9d15723..7bafa91 100644 --- a/DevForge/util.c +++ b/DevForge/util.c @@ -22,7 +22,7 @@ char* devforge_strcat3(const char* str1, const char* str2, const char* str3) { return r; } -char* devforge_strdup(const char* str){ +char* devforge_strdup(const char* str) { char* r = malloc(strlen(str) + 1); memcpy(r, str, strlen(str)); r[strlen(str)] = 0; diff --git a/Module/subversion.c b/Module/subversion.c index 98aac2a..215a8e0 100644 --- a/Module/subversion.c +++ b/Module/subversion.c @@ -27,3 +27,18 @@ /* OF SUCH DAMAGE. */ /* -------------------------------------------------------------------------- */ /* --- END LICENSE --- */ + +#include "../DevForge/devforge.h" +#include "../DevForge/df_log.h" + +#include +#include + +const char mod_type[] = DF_MOD_VCS; + +void (*putlog)(const char* name, const char* log); + +void mod_init(void (*_putlog)(const char* name, const char* log)) { + putlog = _putlog; + putlog(DF_INFO, "Subversion Module init"); +} diff --git a/Module/syslog.c b/Module/syslog.c index c013f36..0e0c189 100644 --- a/Module/syslog.c +++ b/Module/syslog.c @@ -31,26 +31,26 @@ #include "../DevForge/devforge.h" #include "../DevForge/df_log.h" -#include #include +#include const char mod_type[] = DF_MOD_LOG; -void(*putlog)(const char* name, const char* log); +void (*putlog)(const char* name, const char* log); -void mod_init(void(*_putlog)(const char* name, const char* log)){ +void mod_init(void (*_putlog)(const char* name, const char* log)) { putlog = _putlog; putlog(DF_INFO, "Syslog Module init"); } -void mod_log(const char* name, const char* log){ - if(strcmp(name, DF_INFO) == 0){ +void mod_log(const char* name, const char* log) { + if(strcmp(name, DF_INFO) == 0) { syslog(LOG_INFO, log); - }else if(strcmp(name, DF_LOG) == 0){ + } else if(strcmp(name, DF_LOG) == 0) { syslog(LOG_NOTICE, log); - }else if(strcmp(name, DF_ERROR) == 0){ + } else if(strcmp(name, DF_ERROR) == 0) { syslog(LOG_ERR, log); - }else if(strcmp(name, DF_WARN) == 0){ + } else if(strcmp(name, DF_WARN) == 0) { syslog(LOG_WARNING, log); } }