]> Nishi Git Mirror - mandshurica.git/commitdiff
http module
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 13 Apr 2024 06:29:23 +0000 (06:29 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 13 Apr 2024 06:29:23 +0000 (06:29 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@15 f982e544-4a7d-3444-ad1a-fde59a2a69f1

DevForge/config.c
DevForge/devforge.h
Module/Makefile
Module/http.c [new file with mode: 0644]
Module/subversion.c
Module/syslog.c

index 4b6c39806bc047f35a43dc8f9ca766844ff63ab4..bfd3827f696af18cfd7e4a7ce03fd39c592b8240 100644 (file)
@@ -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);
index 8f7e7346b1505c501bd85380a20e31759dd4629a..d1b692a58a9361d40cb5656ef97116b6fceda80f 100644 (file)
 
 #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
index 9c26baa5961ffe89f4a9fdb827d293c20cdb9ade..84a1a21c6fe34c8cfb063b5334a18b5784772571 100644 (file)
@@ -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 (file)
index 0000000..210b402
--- /dev/null
@@ -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;
+}
index 9dac79635bae8e7fd481f032ff96425bdc4c3506..7767f0676a158b734b83216199318ebb2a566ca1 100644 (file)
 #include "../DevForge/df_log.h"
 #include "../DevForge/df_util.h"
 
+#include <stdlib.h>
 #include <string.h>
 #include <syslog.h>
-#include <stdlib.h>
 #include <unistd.h>
 
 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;
                }
index 535c2da35a9a52bcaaa9fb47458ce3dc2c5a9ad0..29a780d5f490b90cd5e5718d5b204b2a32195047 100644 (file)
 
 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;
 }