From: nishi Date: Sat, 13 Apr 2024 06:29:23 +0000 (+0000) Subject: http module X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e9c77ecebb0a7363a7a5c7177a803c1740727249;p=mandshurica.git http module git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@15 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/DevForge/config.c b/DevForge/config.c index 4b6c398..bfd3827 100644 --- a/DevForge/config.c +++ b/DevForge/config.c @@ -56,6 +56,8 @@ void devforge_add_mod(void* lib) { free(old_mods); } +struct devforge_config config = {.devforge_log = devforge_log}; + int devforge_load_config(const char* path) { if(server_root == NULL) { server_root = devforge_strdup(PREFIX); @@ -100,14 +102,14 @@ int devforge_load_config(const char* path) { } void* lib = dlopen(path, RTLD_LAZY); if(lib != NULL) { - int (*init_func)(void (*)(const char*, const char*)) = (int (*)(void (*)(const char*, const char*)))dlsym(lib, "mod_init"); + int (*init_func)(struct devforge_config*) = (int (*)(struct devforge_config*))dlsym(lib, "mod_init"); int ret = 0; - if(init_func != NULL){ - ret = init_func(devforge_log); + if(init_func != NULL) { + ret = init_func(&config); } - if(ret == 0){ + if(ret == 0) { devforge_add_mod(lib); - }else{ + } else { char* str = devforge_strcat3("Could not load the module `", path, "`"); devforge_log(DF_ERROR, str); free(str); @@ -148,6 +150,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/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); diff --git a/DevForge/devforge.h b/DevForge/devforge.h index 8f7e734..d1b692a 100644 --- a/DevForge/devforge.h +++ b/DevForge/devforge.h @@ -35,5 +35,10 @@ #define DF_MOD_LOG "LOG" #define DF_MOD_VCS "VCS" +#define DF_MOD_SRV "SRV" + +struct devforge_config { + void (*devforge_log)(const char*, const char*); +}; #endif diff --git a/Module/Makefile b/Module/Makefile index 9c26baa..84a1a21 100644 --- a/Module/Makefile +++ b/Module/Makefile @@ -6,7 +6,7 @@ EXTRA_LIBS = .PHONY: all clean -all: ./subversion.so ./syslog.so +all: ./subversion.so ./syslog.so ./http.so ./%.so: ./%.o ./util.o $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LIBS) $(EXTRA_LIBS) @@ -14,7 +14,7 @@ all: ./subversion.so ./syslog.so ./util.o: ../DevForge/util.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< -./%.o: ./%.c +./%.o: ./%.c ../DevForge/devforge.h $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< clean: diff --git a/Module/http.c b/Module/http.c new file mode 100644 index 0000000..210b402 --- /dev/null +++ b/Module/http.c @@ -0,0 +1,42 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* DevForge - 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 "../DevForge/devforge.h" +#include "../DevForge/df_log.h" + +const char mod_type[] = DF_MOD_SRV; + +struct devforge_config* config; + +int mod_init(struct devforge_config* _config) { + config = _config; + config->devforge_log(DF_INFO, "HTTP Module init"); + return 0; +} diff --git a/Module/subversion.c b/Module/subversion.c index 9dac796..7767f06 100644 --- a/Module/subversion.c +++ b/Module/subversion.c @@ -32,38 +32,38 @@ #include "../DevForge/df_log.h" #include "../DevForge/df_util.h" +#include #include #include -#include #include const char mod_type[] = DF_MOD_VCS; -void (*putlog)(const char* name, const char* log); +struct devforge_config* config; char* svn_exec = NULL; -int mod_init(void (*_putlog)(const char* name, const char* log)) { - putlog = _putlog; - putlog(DF_INFO, "Subversion Module init"); +int mod_init(struct devforge_config* _config) { + config = _config; + config->devforge_log(DF_INFO, "Subversion Module init"); char* path = getenv("PATH"); - if(path == NULL){ - putlog(DF_ERROR, "PATH is not set!"); + if(path == NULL) { + config->devforge_log(DF_ERROR, "PATH is not set!"); return 1; - }else{ + } else { char* envpath = devforge_strdup(path); int i; int start = 0; - for(i = 0;; i++){ - if(envpath[i] == 0 || envpath[i] == ':'){ + for(i = 0;; i++) { + if(envpath[i] == 0 || envpath[i] == ':') { char oldc = envpath[i]; envpath[i] = 0; - if(strlen(envpath + start) > 0){ + if(strlen(envpath + start) > 0) { char* exec = devforge_strcat(envpath + start, "/svn"); - if(access(exec, X_OK) == 0){ + if(access(exec, X_OK) == 0) { char* found = devforge_strcat3("Found the Subversion executable `", exec, "`"); - putlog(DF_INFO, found); + config->devforge_log(DF_INFO, found); free(found); svn_exec = exec; break; @@ -75,8 +75,8 @@ int mod_init(void (*_putlog)(const char* name, const char* log)) { if(oldc == 0) break; } } - if(svn_exec == NULL){ - putlog(DF_ERROR, "Could not find the Subversion executable!"); + if(svn_exec == NULL) { + config->devforge_log(DF_ERROR, "Could not find the Subversion executable!"); free(envpath); return 1; } diff --git a/Module/syslog.c b/Module/syslog.c index 535c2da..29a780d 100644 --- a/Module/syslog.c +++ b/Module/syslog.c @@ -36,11 +36,11 @@ const char mod_type[] = DF_MOD_LOG; -void (*putlog)(const char* name, const char* log); +struct devforge_config* config; -int mod_init(void (*_putlog)(const char* name, const char* log)) { - putlog = _putlog; - putlog(DF_INFO, "Syslog Module init"); +int mod_init(struct devforge_config* _config) { + config = _config; + config->devforge_log(DF_INFO, "Syslog Module init"); return 0; }