From e4399279888b8a69de154e4168526df834583a12 Mon Sep 17 00:00:00 2001 From: Nishi Date: Fri, 27 Sep 2024 12:55:12 +0000 Subject: [PATCH] psp git-svn-id: file:///raid/svn-personal/tewi/trunk@182 8739d7e6-ffea-ec47-b151-bdff447c6205 --- Common/log.c | 12 ++++++++++++ Makefile | 3 ++- Platform/psp.mk | 12 ++++++++++++ Server/Makefile | 13 +++++++++++-- Server/config.c | 6 +++++- Server/main.c | 18 ++++++++++++++++++ Server/module.c | 38 ++++++++++++++++++++++++-------------- Server/server.c | 9 +++++++-- Server/strptime.c | 2 +- Server/strptime.h | 2 +- config.h.tmpl | 20 ++++++++++++++++++++ 11 files changed, 113 insertions(+), 22 deletions(-) create mode 100644 Platform/psp.mk diff --git a/Common/log.c b/Common/log.c index d8b5123..47e5cec 100644 --- a/Common/log.c +++ b/Common/log.c @@ -11,6 +11,10 @@ #include #include +#ifdef _PSP +#include +#endif + FILE* logfile; bool cm_do_log = false; @@ -22,7 +26,11 @@ void cm_force_log(const char* log) { struct tm* tm = localtime(&t); char date[513]; strftime(date, 512, "%a %b %d %H:%M:%S %Z %Y", tm); +#ifdef _PSP + pspDebugScreenPrintf("[%s] %s\n", date, log); +#else fprintf(logfile, "[%s] %s\n", date, log); +#endif fflush(logfile); } @@ -68,7 +76,11 @@ void cm_log(const char* name, const char* log, ...) { } } +#ifdef _PSP + pspDebugScreenPrintf("%s %s\n", namebuf, result); +#else fprintf(logfile, "%s %s\n", namebuf, result); +#endif va_end(args); free(result); diff --git a/Makefile b/Makefile index 233a056..a9441ad 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ PWD = `pwd` PLATFORM = generic PREFIX = /usr/local +MODULE = ./Module include Platform/$(PLATFORM).mk @@ -10,7 +11,7 @@ FLAGS = PWD=$(PWD) PLATFORM=$(PLATFORM) PREFIX=$(PREFIX) .PHONY: all format clean ./Server ./Common ./Module get-version -all: ./Server ./Module ./Tool/genconf ./Tool/itworks +all: ./Server $(MODULE) ./Tool/genconf ./Tool/itworks ./Tool/option: ./Tool/option.c config.h cc -o $@ ./Tool/option.c diff --git a/Platform/psp.mk b/Platform/psp.mk new file mode 100644 index 0000000..385321f --- /dev/null +++ b/Platform/psp.mk @@ -0,0 +1,12 @@ +# $Id$ + +CC = psp-gcc +AR = psp-ar +CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -I /usr/local/pspdev/psp/sdk/include -D_PSP_FW_VERSION=600 +LDFLAGS = -L /usr/local/pspdev/psp/sdk/lib +LIBS = -lpspgum -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspnet -lpspnet_apctl +EXEC = .elf +LIB = .so +MODULE = +SERVADD = psp-fixup-imports tewi.elf && psp-strip tewi.elf -o tewi_strip.elf +TARGET = tewi.pbp diff --git a/Server/Makefile b/Server/Makefile index be2ec17..68322a9 100644 --- a/Server/Makefile +++ b/Server/Makefile @@ -7,10 +7,19 @@ include $(PWD)/Platform/$(PLATFORM).mk OBJS = version.o main.o config.o server.o http.o module.o strptime.o $(EXTOBJS) $(PREOBJS) -all: tewi$(EXEC) +all: tewi$(EXEC) $(TARGET) + +tewi_strip$(EXEC): tewi$(EXEC) tewi$(EXEC): $(OBJS) ../Common/common.a $(CC) $(LDFLAGS) $(EXTLDFLAGS) -o $@ $(OBJS) $(EXTLIBS) $(LIBS) ../Common/common.a + $(SERVADD) + +tewi.pbp: tewi_strip$(EXEC) param.sfo + pack-pbp $@ param.sfo NULL NULL NULL NULL NULL tewi_strip$(EXEC) NULL + +param.sfo: + mksfoex -d MEMSIZE=1 'Tewi HTTPd' $@ .c.o: $(CC) $(CFLAGS) $(EXTCFLAGS) -c -o $@ $< @@ -19,4 +28,4 @@ tewi.res: tewi.rc ../Binary/tewi.ico $(WINDRES) tewi.rc -O coff -o $@ clean: - rm -f *.o tewi *.exe *.res + rm -f *.o tewi *.exe *.res *.elf *.sfo *.pbp diff --git a/Server/config.c b/Server/config.c index 19098ac..6c3f0c0 100644 --- a/Server/config.c +++ b/Server/config.c @@ -101,7 +101,11 @@ void tw_config_init(void) { config.server_root = cm_strdup(PREFIX); config.server_admin = cm_strdup(SERVER_ADMIN); config.defined[0] = NULL; +#ifdef _PSP + strcpy(config.hostname, "psp"); +#else gethostname(config.hostname, 1024); +#endif #ifdef HAS_CHROOT tw_add_define("HAS_CHROOT"); #endif @@ -410,7 +414,7 @@ int tw_config_read(const char* path) { current->indexes[current->index_count++] = cm_strdup(r[i]); } } else if(cm_strcaseequ(r[0], "ReadmeFile") || cm_strcaseequ(r[0], "Readme")) { - if(cm_strcaseequ(r[0], "Readme")){ + if(cm_strcaseequ(r[0], "Readme")) { cm_force_log("NOTE: Readme directive is deprecated."); } for(i = 1; r[i] != NULL; i++) { diff --git a/Server/main.c b/Server/main.c index 59789ec..1fef989 100644 --- a/Server/main.c +++ b/Server/main.c @@ -25,6 +25,16 @@ #include #endif +#ifdef _PSP +#include +#include + +PSP_MODULE_INFO("Tewi HTTPd", PSP_MODULE_USER, 1, 1); +PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); + +#define printf(...) pspDebugScreenPrintf(__VA_ARGS__) +#endif + extern bool cm_do_log; extern struct tw_config config; extern FILE* logfile; @@ -82,6 +92,10 @@ int main(int argc, char** argv) { SERVICE_TABLE_ENTRY table[] = {{"Tewi HTTPd", servmain}, {NULL, NULL}}; StartServiceCtrlDispatcher(table); #else +#ifdef _PSP + pspDebugScreenInit(); + pspDebugScreenSetXY(0, 0); +#endif int st = startup(argc, argv); if(st != -1) return st; tw_server_loop(); @@ -113,6 +127,7 @@ int startup(int argc, char** argv) { return 1; } confpath = argv[i]; +#ifndef _PSP } else if(strcmp(argv[i], "--logfile") == 0 || strcmp(argv[i], "-l") == 0) { i++; if(argv[i] == NULL) { @@ -127,6 +142,7 @@ int startup(int argc, char** argv) { fprintf(stderr, "Failed to open logfile\n"); return 1; } +#endif } else if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) { printf("Tewi HTTPd Tewi/%s\n", tw_get_version()); printf("Under public domain.\n"); @@ -134,7 +150,9 @@ int startup(int argc, char** argv) { printf("\n"); printf("Usage: %s [--config|-C config] [--verbose|-v] [--version|-V]\n", argv[0]); printf("--config | -C config : Specify config\n"); +#ifndef _PSP printf("--logfile | -l logfile : Specify logfile\n"); +#endif printf("--verbose | -v : Verbose mode\n"); printf("--version | -V : Version information\n"); return 0; diff --git a/Server/module.c b/Server/module.c index 5ca915a..0fc9057 100644 --- a/Server/module.c +++ b/Server/module.c @@ -13,14 +13,23 @@ #include #include +extern struct tw_config config; + +#ifdef _PSP +void* tw_module_load(const char* path) { return NULL; } + +void* tw_module_symbol(void* mod, const char* sym) { return NULL; } + +int tw_module_init(void* mod) { return 1; } + +#else + #ifdef __MINGW32__ #include #else #include #endif -extern struct tw_config config; - void* tw_module_load(const char* path) { char* p = getcwd(NULL, 0); chdir(config.server_root); @@ -46,6 +55,19 @@ void* tw_module_symbol(void* mod, const char* sym) { #endif } +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"); + return 1; + } else { + struct tw_tool tools; + tw_init_tools(&tools); + return mod_init(&config, &tools); + } +} +#endif + void tw_add_version(const char* string) { if(config.extension == NULL) { config.extension = cm_strcat(" ", string); @@ -87,15 +109,3 @@ void tw_init_tools(struct tw_tool* tools) { tools->add_version = tw_add_version; tools->add_define = tw_add_define; } - -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"); - return 1; - } else { - struct tw_tool tools; - tw_init_tools(&tools); - return mod_init(&config, &tools); - } -} diff --git a/Server/server.c b/Server/server.c index 40d9d81..9e8374b 100644 --- a/Server/server.c +++ b/Server/server.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,10 @@ #endif #endif +#ifdef _PSP +#include "strptime.h" +#endif + #ifdef __HAIKU__ #include #endif @@ -506,7 +511,7 @@ int32_t tw_server_pass(void* ptr) { } else if(cm_strcaseequ(req.headers[i], "If-Modified-Since")) { struct tm tm; strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm); -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_PSP) time_t t = 0; struct tm* btm = localtime(&t); cmtime = mktime(&tm); @@ -906,7 +911,7 @@ void tw_server_loop(void) { #endif if(cond) { SOCKADDR claddr; - int clen = sizeof(claddr); + socklen_t clen = sizeof(claddr); int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen); cm_log("Server", "New connection accepted"); #if defined(__MINGW32__) || defined(__HAIKU__) diff --git a/Server/strptime.c b/Server/strptime.c index c10ccf8..fb584c9 100644 --- a/Server/strptime.c +++ b/Server/strptime.c @@ -35,7 +35,7 @@ //#include //__RCSID("$NetBSD: strptime.c,v 1.62 2017/08/24 01:01:09 ginsbach Exp $"); -#ifdef __MINGW32__ +#if defined(__MINGW32__) #include #include diff --git a/Server/strptime.h b/Server/strptime.h index bc168bf..a26974b 100644 --- a/Server/strptime.h +++ b/Server/strptime.h @@ -7,7 +7,7 @@ extern "C" { #include -#ifdef _WIN32 +#if defined(_WIN32) || defined(_PSP) char* strptime(const char *buf, const char *fmt, struct tm *tm); #endif diff --git a/config.h.tmpl b/config.h.tmpl index da0c04e..4b73646 100644 --- a/config.h.tmpl +++ b/config.h.tmpl @@ -27,6 +27,26 @@ /* Windows should not have chroot */ #endif +#if defined(_PSP) && !defined(NO_IPV6) +#define NO_IPV6 +/* PSP does not have IPv6 */ +#endif + +#if defined(_PSP) && defined(USE_POLL) +#undef USE_POLL +/* Force select(2) for PSP */ +#endif + +#if defined(_PSP) && defined(HAS_CHROOT) +#undef HAS_CHROOT +/* PSP should not have chroot */ +#endif + +#if defined(_PSP) && !defined(NO_GETADDRINFO) +#define NO_GETADDRINFO +/* PSP should not have getaddrinfo */ +#endif + #endif /* -- 2.43.0