+++ /dev/null
-/* $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;
-}
-DevForge - Build Automation
+Mandshurica - Build Automation
# $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::
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
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
/* $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>
#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++)
;
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++)
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) {
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) {
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");
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);
}
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;
}
/* $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;
/* $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) {
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;
}
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]);
}
}
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);
return ret;
}
}
- devforge_log(DF_ERROR, "Server module was not loaded!");
+ mandshurica_log(MS_ERROR, "Server module was not loaded!");
}
/* $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
/* $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
;
/* $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
/* $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
--- /dev/null
+/* $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;
+}
./%.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:
/* $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;
}
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));
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);
}
}
/* $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++) {
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;
}
}
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;
}
/* $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);
}
}