#include <stdlib.h>
#include <stdarg.h>
+#ifdef _PSP
+#include <pspdebug.h>
+#endif
+
FILE* logfile;
bool cm_do_log = false;
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);
}
}
}
+#ifdef _PSP
+ pspDebugScreenPrintf("%s %s\n", namebuf, result);
+#else
fprintf(logfile, "%s %s\n", namebuf, result);
+#endif
va_end(args);
free(result);
PWD = `pwd`
PLATFORM = generic
PREFIX = /usr/local
+MODULE = ./Module
include Platform/$(PLATFORM).mk
.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
--- /dev/null
+# $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
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 $@ $<
$(WINDRES) tewi.rc -O coff -o $@
clean:
- rm -f *.o tewi *.exe *.res
+ rm -f *.o tewi *.exe *.res *.elf *.sfo *.pbp
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
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++) {
#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;
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();
return 1;
}
confpath = argv[i];
+#ifndef _PSP
} else if(strcmp(argv[i], "--logfile") == 0 || strcmp(argv[i], "-l") == 0) {
i++;
if(argv[i] == NULL) {
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");
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;
#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);
#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);
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);
- }
-}
#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
} 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);
#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__)
//#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>
#include <time.h>
-#ifdef _WIN32
+#if defined(_WIN32) || defined(_PSP)
char* strptime(const char *buf, const char *fmt, struct tm *tm);
#endif
/* 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
/*