]> Git repositories of Nishi - tewi.git/commitdiff
custom config
authorNishi <nishi@nishi.boats>
Tue, 17 Sep 2024 12:20:48 +0000 (12:20 +0000)
committerNishi <nishi@nishi.boats>
Tue, 17 Sep 2024 12:20:48 +0000 (12:20 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@39 8739d7e6-ffea-ec47-b151-bdff447c6205

Module/Makefile
Module/mod_cgi.c [new file with mode: 0644]
Server/config.c
Server/tw_module.h
example.conf

index abf0b73372ca97da649c815cf23c14e6287e383b..fcf8c4b4af989bcfe60aa0730ae2ab81c4ae9e80 100644 (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)
diff --git a/Module/mod_cgi.c b/Module/mod_cgi.c
new file mode 100644 (file)
index 0000000..b4ec678
--- /dev/null
@@ -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; }
index 95592fd6baf259e58bd5be946384a0c7d61a46c5..18957f04c9bd527027f6e12ae5e4937ecc617d49 100644 (file)
@@ -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);
index df02072915c1ccf2365b95acf59aa3cdba4e692a..17c81bb82ebeef327516841f1bcb47c5b8be95de 100644 (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);
index e64da91e13a47062c377d0c6b9b02f2be89c015e..9e662c5f7b2030682a815613a8a32362151965dc 100644 (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