custom config

git-svn-id: file:///raid/svn-personal/tewi/trunk@39 8739d7e6-ffea-ec47-b151-bdff447c6205
This commit is contained in:
Nishi 2024-09-17 12:20:48 +00:00
parent 08a68d2881
commit 2d552b27ab
5 changed files with 55 additions and 6 deletions

View File

@ -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)

16
Module/mod_cgi.c Normal file
View File

@ -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; }

View File

@ -295,10 +295,34 @@ int tw_config_read(const char* path) {
current->readmes[current->readme_count++] = cm_strdup(r[i]);
}
} else {
if(r[0] != NULL) {
cm_log("Config", "Unknown directive `%s' at line %d", r[0], ln);
}
stop = 1;
if(r[0] != NULL) {
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;
}
}
}
for(i = 0; r[i] != NULL; i++) free(r[i]);
free(r);

View File

@ -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);

View File

@ -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