From 7ecede39525bc6f426c132bbfac01baae8bb933f Mon Sep 17 00:00:00 2001 From: Nishi Date: Sun, 13 Oct 2024 23:22:06 +0000 Subject: [PATCH] dll does not work somehow git-svn-id: file:///raid/svn-personal/tewi/trunk@313 8739d7e6-ffea-ec47-b151-bdff447c6205 --- Module/mod_cgi.c | 6 +++--- Module/mod_example.c | 6 +++--- Module/mod_proxy.c | 6 +++--- README | 1 + README.tmpl | 1 + Server/module.c | 20 ++++++++++++++------ Server/tw_module.h | 15 ++++++++++++--- 7 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Module/mod_cgi.c b/Module/mod_cgi.c index 6659043..da9e232 100644 --- a/Module/mod_cgi.c +++ b/Module/mod_cgi.c @@ -4,20 +4,20 @@ #include -int mod_init(struct tw_config* config, struct tw_tool* tools) { +int MODULE_DECL 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) { +int MODULE_DECL mod_config(struct tw_tool* tools, char** argv, int argc) { if(cm_strcaseequ(argv[0], "AllowCGI")) { return TW_CONFIG_PARSED; } return TW_CONFIG_NOTME; } -int mod_request(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res) { +int MODULE_DECL mod_request(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res) { res->status = 403; return TW_MODULE_STOP; } diff --git a/Module/mod_example.c b/Module/mod_example.c index a554de5..6472128 100644 --- a/Module/mod_example.c +++ b/Module/mod_example.c @@ -3,12 +3,12 @@ #include -int mod_init(struct tw_config* config, struct tw_tool* tools) { +int MODULE_DECL mod_init(struct tw_config* config, struct tw_tool* tools) { tools->log("Example", "This is an example module"); tools->add_version("Example/0.0"); return 0; } -int mod_config(struct tw_tool* tools, char** argv, int argc) { return TW_CONFIG_PARSED; } +int MODULE_DECL mod_config(struct tw_tool* tools, char** argv, int argc) { return TW_CONFIG_PARSED; } -int mod_request(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res) { return TW_MODULE_ERROR(403); } +int MODULE_DECL mod_request(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res) { return TW_MODULE_ERROR(403); } diff --git a/Module/mod_proxy.c b/Module/mod_proxy.c index 4c09144..96076a6 100644 --- a/Module/mod_proxy.c +++ b/Module/mod_proxy.c @@ -4,12 +4,12 @@ #include -int mod_init(struct tw_config* config, struct tw_tool* tools) { +int MODULE_DECL mod_init(struct tw_config* config, struct tw_tool* tools) { tools->log("CGI", "Initializing Proxy module"); tools->add_version("Proxy/1.0"); return 0; } -int mod_config(struct tw_tool* tools, char** argv, int argc) { return TW_CONFIG_NOTME; } +int MODULE_DECL mod_config(struct tw_tool* tools, char** argv, int argc) { return TW_CONFIG_NOTME; } -int mod_request(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res) { return TW_MODULE_PASS; } +int MODULE_DECL mod_request(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res) { return TW_MODULE_PASS; } diff --git a/README b/README index 8a1286b..064721e 100644 --- a/README +++ b/README @@ -44,6 +44,7 @@ OpenBSD Working Haiku Working Minix Working UnixWare Working on 7.1.1 +OS/2 Mostly working, module is broken. Help required! PlayStation Portable Working, missing module support TODO: Get multi-threading working (maybe) PlayStation 2 Not working diff --git a/README.tmpl b/README.tmpl index b40ced2..b32db4d 100644 --- a/README.tmpl +++ b/README.tmpl @@ -44,6 +44,7 @@ OpenBSD Working Haiku Working Minix Working UnixWare Working on 7.1.1 +OS/2 Mostly working, module is broken. Help required! PlayStation Portable Working, missing module support TODO: Get multi-threading working (maybe) PlayStation 2 Not working diff --git a/Server/module.c b/Server/module.c index d763900..e92aece 100644 --- a/Server/module.c +++ b/Server/module.c @@ -29,6 +29,7 @@ int tw_module_init(void* mod) { return 1; } #if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) #ifdef __OS2__ #define INCL_DOSMODULEMGR +#define INCL_DOSERRORS #include #else #include @@ -42,13 +43,16 @@ void* tw_module_load(const char* path) { char* p = getcwd(NULL, 0); void* lib; char tmp[512]; - unsigned long l; +#ifdef __OS2__ + HMODULE mod; +#endif chdir(config.server_root); #if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) #ifdef __OS2__ - lib = NULL; - l = (unsigned long)lib; - DosLoadModule(tmp, 512, path, &l); + if(DosLoadModule(tmp, 512, path, &mod) != NO_ERROR){ + return NULL; + } + lib = (void*)mod; #else lib = LoadLibraryA(path); #endif @@ -67,7 +71,11 @@ void* tw_module_symbol(void* mod, const char* sym) { #if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) #ifdef __OS2__ void* ret; - DosQueryProcAddr((unsigned long)mod, 0, sym, (PFN*)&ret); + APIRET rc; + if((rc = DosQueryProcAddr((HMODULE)mod, 0, sym, (PFN*)&ret)) != NO_ERROR){ + cm_log("Module", "OS/2 error %d", (int)rc); + return NULL; + } return ret; #else return GetProcAddress(mod, sym); @@ -80,7 +88,7 @@ void* tw_module_symbol(void* mod, const char* sym) { int tw_module_init(void* mod) { tw_mod_init_t mod_init = (tw_mod_init_t)tw_module_symbol(mod, "mod_init"); if(mod_init == NULL) { - cm_log("Module", "Could not init a module"); + cm_log("Module", "Could not find a init call"); return 1; } else { struct tw_tool tools; diff --git a/Server/tw_module.h b/Server/tw_module.h index 890fbc1..e50d6ec 100644 --- a/Server/tw_module.h +++ b/Server/tw_module.h @@ -10,6 +10,15 @@ extern "C" { #include "tw_config.h" #include "tw_http.h" +#if defined(__OS2__) +#define INCL_DOSMODULEMGR +#define INCL_DOSERRORS +#include +#define MODULE_DECL APIENTRY +#else +#define MODULE_DECL +#endif + struct tw_tool { void (*log)(const char* name, const char* log, ...); void (*add_version)(const char* string); @@ -37,9 +46,9 @@ enum TW_MODULE_RETURN { #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); +typedef int (MODULE_DECL *tw_mod_init_t)(struct tw_config* config, struct tw_tool* tools); +typedef int (MODULE_DECL *tw_mod_request_t)(struct tw_tool* tools, struct tw_http_request* req, struct tw_http_response* res); +typedef int (MODULE_DECL *tw_mod_config_t)(struct tw_tool* tools, char** argv, int argc); #ifdef SOURCE void* tw_module_load(const char* path); -- 2.45.2