# HG changeset patch # User Olaf Wintermann # Date 1484499196 -3600 # Node ID d050449c3b9e6bf8ef7f96254b554f93c7ff0b3c # Parent a9591a91c004b976bcd29db49fc3bb83d85bb9bf ported io.c and some headers to windows diff -r a9591a91c004 -r d050449c3b9e make/mingw.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/mingw.mk Sun Jan 15 17:53:16 2017 +0100 @@ -0,0 +1,38 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2013 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +CFLAGS = -std=gnu99 -g +LDFLAGS = -rdynamic -Wl,-R,'$$ORIGIN/../lib' + +CC = gcc +CXX = g++ +LD = g++ + +SHLIB_CFLAGS = -fPIC +SHLIB_LDFLAGS = -shared + diff -r a9591a91c004 -r d050449c3b9e make/windows.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/windows.mk Sun Jan 15 17:53:16 2017 +0100 @@ -0,0 +1,42 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2013 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + + +# compiler and linker flags +CFLAGS += -DWINDOWS +LDFLAGS += + + +# platform dependend source files +PLATFORM_DAEMONOBJ = event_windows.o + +# platform dependend vars +OBJ_EXT = .o +LIB_EXT = .dll +APP_EXT = .exe + diff -r a9591a91c004 -r d050449c3b9e src/server/public/auth.h --- a/src/server/public/auth.h Sat Jan 14 11:27:55 2017 +0100 +++ b/src/server/public/auth.h Sun Jan 15 17:53:16 2017 +0100 @@ -35,6 +35,11 @@ extern "C" { #endif +#ifdef XP_WIN32 +typedef int uid_t; +typedef int gid_t; +#endif + typedef struct auth_db AuthDB; typedef struct user User; diff -r a9591a91c004 -r d050449c3b9e src/server/public/nsapi.h --- a/src/server/public/nsapi.h Sat Jan 14 11:27:55 2017 +0100 +++ b/src/server/public/nsapi.h Sun Jan 15 17:53:16 2017 +0100 @@ -369,6 +369,7 @@ #include #include #include +#include // TODO: works only with mingw #include #endif /* XP_WIN32 */ @@ -380,6 +381,7 @@ #include #include #include +#include /* --- End native platform includes --- */ @@ -651,8 +653,9 @@ #endif #ifndef SEMAPHORE_T -typedef void *SEMAPHORE; -#define SEMAPHORE_T void * +// TODO: fix +//typedef void *SEMAPHORE; +//#define SEMAPHORE_T void * #endif /* !SEMAPHORE_T */ #define SESSION_HASHSIZE 5 @@ -699,13 +702,14 @@ * FuncPtr is a pointer to an NSAPI SAF function */ +// TODO: fix typedefs #ifdef XP_UNIX typedef int Func(pblock *, Session *, Request *); // new func executor typedef int FuncExec(FuncStruct *, pblock *, Session *, Request *); #else /* XP_WIN32 */ typedef int _cdecl Func(pblock *, Session *, Request *); -typedef int _cdecl uncExec(FuncStruct *, pblock *, Session *, Request *); +typedef int _cdecl FuncExec(FuncStruct *, pblock *, Session *, Request *); #endif /* XP_WIN32 */ typedef Func *FuncPtr; @@ -859,7 +863,12 @@ /* Define a handle for a thread */ //typedef void* SYS_THREAD; + +#ifdef XP_UNIX typedef pthread_t SYS_THREAD; +#else +typedef void* SYS_THREAD; +#endif /* Define an error value for the thread handle */ #define SYS_THREAD_ERROR NULL @@ -1534,7 +1543,7 @@ #ifdef XP_WIN32 -typedef HANDLE pid_t; +//typedef HANDLE pid_t; // TODO #define ERROR_PIPE \ (ERROR_BROKEN_PIPE | ERROR_BAD_PIPE | \ @@ -1557,20 +1566,20 @@ } #ifdef INTNSAPI -NSAPI_PUBLIC extern nsapi_dispatch_t *__nsapi30_table; +//NSAPI_PUBLIC extern nsapi_dispatch_t *__nsapi30_table; #if NSAPI_VERSION >= 302 -NSAPI_PUBLIC extern nsapi302_dispatch_t *__nsapi302_table; +//NSAPI_PUBLIC extern nsapi302_dispatch_t *__nsapi302_table; #endif /* NSAPI_VERSION >= 302 */ #if NSAPI_VERSION >= 303 -NSAPI_PUBLIC extern nsapi303_dispatch_t *__nsapi303_table; +//NSAPI_PUBLIC extern nsapi303_dispatch_t *__nsapi303_table; #endif /* NSAPI_VERSION >= 303 */ #else -__declspec(dllimport) nsapi_dispatch_t *__nsapi30_table; +//__declspec(dllimport) nsapi_dispatch_t *__nsapi30_table; #if NSAPI_VERSION >= 302 -__declspec(dllimport) nsapi302_dispatch_t *__nsapi302_table; +//__declspec(dllimport) nsapi302_dispatch_t *__nsapi302_table; #endif /* NSAPI_VERSION >= 302 */ #if NSAPI_VERSION >= 303 -__declspec(dllimport) nsapi303_dispatch_t *__nsapi303_table; +//__declspec(dllimport) nsapi303_dispatch_t *__nsapi303_table; #endif /* NSAPI_VERSION >= 303 */ #endif /* INTNSAPI */ diff -r a9591a91c004 -r d050449c3b9e src/server/util/io.c --- a/src/server/util/io.c Sat Jan 14 11:27:55 2017 +0100 +++ b/src/server/util/io.c Sun Jan 15 17:53:16 2017 +0100 @@ -32,8 +32,15 @@ #include #include + +#ifdef XP_UNIX #include #include +#endif + +#ifdef XP_WIN32 + +#endif #if defined(LINUX) || defined(SOLARIS) #include @@ -44,10 +51,16 @@ #else #define WS_SENDFILE #endif +#endif + +#ifdef WS_SENDFILE +#define NET_SYS_SENDFILE net_sys_sendfile #else -#define net_sys_sendfile net_fallback_sendfile +#define NET_SYS_SENDFILE net_fallback_sendfile #endif + + #include "../daemon/vfs.h" #include "io.h" #include "pool.h" @@ -57,7 +70,7 @@ (io_write_f)net_sys_write, (io_writev_f)net_sys_writev, (io_read_f)net_sys_read, - (io_sendfile_f)net_sys_sendfile, + (io_sendfile_f)NET_SYS_SENDFILE, (io_close_f)net_sys_close, NULL }; @@ -85,7 +98,7 @@ * SysStream implementation */ -IOStream* sysstream_new(pool_handle_t *pool, int fd) { +IOStream* sysstream_new(pool_handle_t *pool, SYS_SOCKET fd) { SysStream *st = pool_malloc(pool, sizeof(SysStream)); st->st = native_io_funcs; st->fd = fd; @@ -160,7 +173,7 @@ #elif defined(XP_WIN32) ssize_t net_sys_write(SysStream *st, void *buf, size_t nbytes) { - int ret = send(st->socket, buf, nbytes, 0); + int ret = send(st->fd, buf, nbytes, 0); if(ret == SOCKET_ERROR) { return IO_ERROR; } @@ -172,7 +185,7 @@ } ssize_t net_sys_read(SysStream *st, void *buf, size_t nbytes) { - int ret = recv(st->socket, buf, nbytes, 0); + int ret = recv(st->fd, buf, nbytes, 0); if(ret == SOCKET_ERROR) { return IO_ERROR; } @@ -184,7 +197,7 @@ } void net_sys_close(SysStream *st) { - closesocket(st->socket); + closesocket(st->fd); } #endif diff -r a9591a91c004 -r d050449c3b9e src/server/util/io.h --- a/src/server/util/io.h Sat Jan 14 11:27:55 2017 +0100 +++ b/src/server/util/io.h Sun Jan 15 17:53:16 2017 +0100 @@ -42,6 +42,12 @@ extern "C" { #endif +#ifdef XP_UNIX +#define SYS_SOCKET int +#elif defined(XP_WIN32) +#define SYS_SOCKET SOCKET +#endif + typedef struct IOStream IOStream; typedef struct SysStream SysStream; typedef struct HttpStream HttpStream; @@ -67,7 +73,7 @@ #ifdef XP_UNIX int fd; #elif defined(XP_WIN32) - SOCKET socket; + SOCKET fd; #endif }; @@ -89,7 +95,7 @@ /* system stream */ -IOStream* sysstream_new(pool_handle_t *pool, int fd); +IOStream* sysstream_new(pool_handle_t *pool, SYS_SOCKET fd); ssize_t net_sys_write(SysStream *st, void *buf, size_t nbytes); ssize_t net_sys_writev(SysStream *st, struct iovec *iovec, int iovcnt);