From: Nishi Date: Tue, 17 Sep 2024 12:20:48 +0000 (+0000) Subject: custom config X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=2d552b27ab648c5cf76c41250f7b27460aca83d7;p=tewi.git custom config git-svn-id: file:///raid/svn-personal/tewi/trunk@39 8739d7e6-ffea-ec47-b151-bdff447c6205 --- diff --git a/Module/Makefile b/Module/Makefile index abf0b73..fcf8c4b 100644 --- a/Module/Makefile +++ b/Module/Makefile @@ -5,7 +5,7 @@ include $(PWD)/Platform/$(PLATFORM).mk .PHONY: all clean .SUFFIXES: .c .o .so -all: mod_example.so +all: mod_example.so mod_cgi.so .o.so: $(CC) $(LDFLAGS) -shared -o $@ $< ../Common/common.a $(LIBS) diff --git a/Module/mod_cgi.c b/Module/mod_cgi.c new file mode 100644 index 0000000..b4ec678 --- /dev/null +++ b/Module/mod_cgi.c @@ -0,0 +1,16 @@ +/* $Id$ */ + +#include "../Server/tw_module.h" + +int mod_init(struct tw_config* config, struct tw_tool* tools) { + tools->log("CGI", "Initializing CGI module"); + tools->add_version("CGI/1.1"); + return 0; +} + +int mod_config(struct tw_tool* tools, char** argv, int argc) { + printf("args %d\n", argc); + return TW_CONFIG_ERROR; +} + +int mod_request(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res) { return TW_MODULE_PASS; } diff --git a/Server/config.c b/Server/config.c index 95592fd..18957f0 100644 --- a/Server/config.c +++ b/Server/config.c @@ -295,10 +295,34 @@ int tw_config_read(const char* path) { current->readmes[current->readme_count++] = cm_strdup(r[i]); } } else { + stop = 1; if(r[0] != NULL) { - cm_log("Config", "Unknown directive `%s' at line %d", r[0], ln); + int argc; + for(argc = 0; r[argc] != NULL; argc++) + ; + stop = 0; + int i; + bool called = false; + struct tw_tool tools; + tw_init_tools(&tools); + for(i = 0; i < config.module_count; i++) { + tw_mod_config_t mod_config = (tw_mod_config_t)tw_module_symbol(config.modules[i], "mod_config"); + int resp; + if(mod_config != NULL && (resp = mod_config(&tools, r, argc)) == TW_CONFIG_PARSED) { + called = true; + break; + } + if(resp == TW_CONFIG_ERROR) { + stop = 1; + called = true; + break; + } + } + if(!called) { + cm_log("Config", "Unknown directive `%s' at line %d", r[0], ln); + stop = 1; + } } - stop = 1; } for(i = 0; r[i] != NULL; i++) free(r[i]); free(r); diff --git a/Server/tw_module.h b/Server/tw_module.h index df02072..17c81bb 100644 --- a/Server/tw_module.h +++ b/Server/tw_module.h @@ -14,15 +14,24 @@ struct tw_tool { enum TW_MODULE_RETURN { _TW_MODULE_PASS = 0, /* Pass to the next module. */ _TW_MODULE_STOP, /* Do not pass to the next module. */ - _TW_MODULE_ERROR /* Error, and do not pass to the next module. */ + _TW_MODULE_ERROR, /* Error, and do not pass to the next module. */ + + _TW_CONFIG_PARSED, /* Got parsed */ + _TW_CONFIG_NOTME, /* Did not parse */ + _TW_CONFIG_ERROR /* Error */ }; #define TW_MODULE_PASS _TW_MODULE_PASS #define TW_MODULE_STOP _TW_MODULE_STOP #define TW_MODULE_ERROR(x) (_TW_MODULE_ERROR | ((x) << 8)) +#define TW_CONFIG_PARSED _TW_CONFIG_PARSED +#define TW_CONFIG_NOTME _TW_CONFIG_NOTME +#define TW_CONFIG_ERROR _TW_CONFIG_ERROR + typedef int (*tw_mod_init_t)(struct tw_config* config, struct tw_tool* tools); typedef int (*tw_mod_request_t)(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res); +typedef int (*tw_mod_config_t)(struct tw_tool* tools, char** argv, int argc); void* tw_module_load(const char* path); void* tw_module_symbol(void* mod, const char* sym); diff --git a/example.conf b/example.conf index e64da91..9e662c5 100644 --- a/example.conf +++ b/example.conf @@ -1,7 +1,7 @@ # $Id$ # This is an example config -#LoadModule /home/nishi/SVN/tewi/trunk/Module/mod_example.so +LoadModule /home/nishi/SVN/tewi/trunk/Module/mod_cgi.so Listen 80 ListenSSL 443