]> Git repositories of Nishi - tewi.git/commitdiff
psp
authorNishi <nishi@nishi.boats>
Fri, 27 Sep 2024 12:55:12 +0000 (12:55 +0000)
committerNishi <nishi@nishi.boats>
Fri, 27 Sep 2024 12:55:12 +0000 (12:55 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@182 8739d7e6-ffea-ec47-b151-bdff447c6205

Common/log.c
Makefile
Platform/psp.mk [new file with mode: 0644]
Server/Makefile
Server/config.c
Server/main.c
Server/module.c
Server/server.c
Server/strptime.c
Server/strptime.h
config.h.tmpl

index d8b512304039ff5b45e392cb5d2f4f5d4528be12..47e5cecc957e04cca8ad7dd08b6631d17d222b7c 100644 (file)
 #include <stdlib.h>
 #include <stdarg.h>
 
+#ifdef _PSP
+#include <pspdebug.h>
+#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);
index 233a05683cef4513b8e7dc93212f77a59fbcdc0d..a9441ad56ad44dcf592b3a7737145e8fddacaf45 100644 (file)
--- 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 (file)
index 0000000..385321f
--- /dev/null
@@ -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
index be2ec178cde6f1d336518433a287eed5ad4fccf0..68322a9e4ddb7ba4211a7b7e0743c8ef654c68be 100644 (file)
@@ -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
index 19098aca903326fd12ffbe3cb204ad5685011974..6c3f0c01093fea5501e2c1cf76b0783945a18cc8 100644 (file)
@@ -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++) {
index 59789eca3f08e82ff16993796e73ec56d26ebfef..1fef989983cbe0453dd504ac8ed24c625d8d5753 100644 (file)
 #include <windows.h>
 #endif
 
+#ifdef _PSP
+#include <pspkernel.h>
+#include <pspdebug.h>
+
+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;
index 5ca915a537e43754e77a92913f3cb2040ffa5513..0fc9057ca418f0195e585c50c95fa33351f5b930 100644 (file)
 #include <unistd.h>
 #include <stdlib.h>
 
+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 <windows.h>
 #else
 #include <dlfcn.h>
 #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);
-       }
-}
index 40d9d817483ab1c9767d98df2928d2cf281bb99d..9e8374b8a36ff4853ba5111927a6082e3196783b 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <time.h>
 
 #include <cm_string.h>
 #endif
 #endif
 
+#ifdef _PSP
+#include "strptime.h"
+#endif
+
 #ifdef __HAIKU__
 #include <OS.h>
 #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__)
index c10ccf8fb783befe25020542f4be9f72d578b7e9..fb584c94e08844536d56a9c739619bdab0e4d1b2 100644 (file)
@@ -35,7 +35,7 @@
 //#include <sys/cdefs.h>
 //__RCSID("$NetBSD: strptime.c,v 1.62 2017/08/24 01:01:09 ginsbach Exp $");
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__)
 
 #include <ctype.h>
 #include <string.h>
index bc168bf9ffd49f7546053bbfb3194ec3a609df48..a26974b134e33eca352a1315397ba05cbe3b1e6c 100644 (file)
@@ -7,7 +7,7 @@ extern "C" {
 
 #include <time.h>
 
-#ifdef _WIN32
+#if defined(_WIN32) || defined(_PSP)
 char* strptime(const char *buf, const char *fmt, struct tm *tm);
 #endif
 
index da0c04ef30d9011c7b92e93ec0f982f42661888a..4b73646ff20af2b21af6aaef121375ce941df466 100644 (file)
 /* 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
 
 /*