]> Nishi Git Mirror - mandshurica.git/commitdiff
rename
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sun, 14 Apr 2024 02:51:00 +0000 (02:51 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sun, 14 Apr 2024 02:51:00 +0000 (02:51 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@21 f982e544-4a7d-3444-ad1a-fde59a2a69f1

16 files changed:
DevForge/util.c [deleted file]
HEADER
Makefile
Mandshurica/Makefile [moved from DevForge/Makefile with 65% similarity]
Mandshurica/config.c [moved from DevForge/config.c with 75% similarity]
Mandshurica/log.c [moved from DevForge/log.c with 91% similarity]
Mandshurica/main.c [moved from DevForge/main.c with 84% similarity]
Mandshurica/mandshurica.h [moved from DevForge/devforge.h with 83% similarity]
Mandshurica/ms_config.h [moved from DevForge/df_config.h with 82% similarity]
Mandshurica/ms_log.h [moved from DevForge/df_log.h with 87% similarity]
Mandshurica/ms_util.h [moved from DevForge/df_util.h with 81% similarity]
Mandshurica/util.c [new file with mode: 0644]
Module/Makefile
Module/http.c
Module/subversion.c
Module/syslog.c

diff --git a/DevForge/util.c b/DevForge/util.c
deleted file mode 100644 (file)
index 7bafa91..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* $Id$ */
-/* --- START LICENESE --- */
-/* --- END LICENSE --- */
-
-#include "df_util.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-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 54b866cef6dc5a5ad114b7a52c37121294184f29..d62c294a1f04290fe4e067a94f0b8966e3568382 100644 (file)
--- a/HEADER
+++ b/HEADER
@@ -1 +1 @@
-DevForge - Build Automation
+Mandshurica - Build Automation
index 0d91d2e79abe5f1041b36a845e5dce515ae7e8c0..8b243a8e6a2f6b52c5f51291f9029d7289a3ed9f 100644 (file)
--- 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
similarity index 65%
rename from DevForge/Makefile
rename to Mandshurica/Makefile
index 9ce892e7383adc228eff8a15c586b6253eabd83a..c3f4ebe413095d8ae38e9f5c9e6083aa06082d64 100644 (file)
@@ -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
similarity index 75%
rename from DevForge/config.c
rename to Mandshurica/config.c
index a4559ff8749932689fd56f2e20715357ccbd4600..4f6a24bbb7498a9fdd40dc5238118be33395fa67 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- 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 <dlfcn.h>
 #include <errno.h>
@@ -43,8 +43,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-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;
        }
 
similarity index 91%
rename from DevForge/log.c
rename to Mandshurica/log.c
index e62b1204e7219efc09e6b9102281ec4fc1612480..cf80584efd8d3553bd9d5c5de87c66f538208030 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- 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 <dlfcn.h>
 #include <stdbool.h>
 #include <string.h>
 #include <time.h>
 
-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;
similarity index 84%
rename from DevForge/main.c
rename to Mandshurica/main.c
index 40c3546f4d644a276698fd518f49ccfe81f3d25f..9b215d6d4ec8a2574881194672c941489eee29cc 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- 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 <dlfcn.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 
-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!");
 }
similarity index 83%
rename from DevForge/devforge.h
rename to Mandshurica/mandshurica.h
index 329d21be28a9c673d0625a43add06cf5f48043f1..820971a381d4c80f3394b8b233ab389e1aca204e 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- 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
similarity index 82%
rename from DevForge/df_config.h
rename to Mandshurica/ms_config.h
index 2e11ff5498b7dba3da84bc83657712c89a78ddd2..ddc9e5f641811ee7753a390f38490057c1b9be77 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- END LICENSE --- */
 
-#ifndef __DEVFORGE_DF_CONFIG_H__
-#define __DEVFORGE_DF_CONFIG_H__
+#ifndef __MANDSHURICA_MS_CONFIG_H__
+#define __MANDSHURICA_MS_CONFIG_H__
 
 #include <pthread.h>
 #include <stdbool.h>
 #include <stddef.h>
 
-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
     ;
similarity index 87%
rename from DevForge/df_log.h
rename to Mandshurica/ms_log.h
index 0ff4f994e1c5be2f8d9f1d2500ad9fcc0a3f72ee..7de8aa852563d28adf75b2ba85b5f81bc6aa061f 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- 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
similarity index 81%
rename from DevForge/df_util.h
rename to Mandshurica/ms_util.h
index 136469b7e318c436192d4ae114eb27b3f305f4eb..2178e72b084283c6d150043f217365e1db303ee9 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- 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 <stdbool.h>
+
+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 (file)
index 0000000..41f2720
--- /dev/null
@@ -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 <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+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;
+}
index 84a1a21c6fe34c8cfb063b5334a18b5784772571..c538330fb71ecefa8df4b53e0869f6a55e8486ae 100644 (file)
@@ -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:
index e13052bebcb40b87d515c1f092b70ab4a4dd6e77..7f05ff82de358f81445e6493393c2ed8bc40b264 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- 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 <signal.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
-#include <signal.h>
-#include <stdbool.h>
 #include <sys/types.h>
+#include <unistd.h>
 
-#include <sys/socket.h>
-#include <netinet/tcp.h>
 #include <arpa/inet.h>
+#include <netinet/tcp.h>
+#include <sys/socket.h>
 
-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);
                }
        }
index 7767f0676a158b734b83216199318ebb2a566ca1..6796739a6a1e074fa9390c290c90c302549c2baa 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- 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 <stdlib.h>
 #include <string.h>
 #include <syslog.h>
 #include <unistd.h>
 
-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;
                }
index 29a780d5f490b90cd5e5718d5b204b2a32195047..c87de5c5e1c8dca24e37e45f87117333c2fd7c54 100644 (file)
@@ -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 */
 /* -------------------------------------------------------------------------- */
 /* --- END LICENSE --- */
 
-#include "../DevForge/devforge.h"
-#include "../DevForge/df_log.h"
+#include "../Mandshurica/mandshurica.h"
+#include "../Mandshurica/ms_log.h"
 
 #include <string.h>
 #include <syslog.h>
 
-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);
        }
 }