# HG changeset patch # User Olaf Wintermann # Date 1371727627 -7200 # Node ID 4a10bc0ee80d98475423f76650bf8aaacc84fab2 # Parent f5102a892ed4122665a4a4b6f9508f559a92ec75 compiles on os x diff -r f5102a892ed4 -r 4a10bc0ee80d .hgignore --- a/.hgignore Mon May 27 12:28:56 2013 +0200 +++ b/.hgignore Thu Jun 20 13:27:07 2013 +0200 @@ -1,3 +1,4 @@ relre:^work/.*$ relre:^build/.*$ relre:^config.mk$ +relre:DS_Store diff -r f5102a892ed4 -r 4a10bc0ee80d config.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.mk Thu Jun 20 13:27:07 2013 +0200 @@ -0,0 +1,15 @@ +# +# config.mk generated by configure +# + +INSTALL_DIR = /Users/olaf/Projekte/webserver/work +HOST = m4 + + +include $(BUILD_ROOT)/make/clang.mk +include $(BUILD_ROOT)/make/osx.mk + +CFLAGS += -I/opt/local/include +LDFLAGS += -L/opt/local/lib -lssl -lcrypto + + diff -r f5102a892ed4 -r 4a10bc0ee80d configure --- a/configure Mon May 27 12:28:56 2013 +0200 +++ b/configure Thu Jun 20 13:27:07 2013 +0200 @@ -64,8 +64,8 @@ fi if [ $OS = Darwin ]; then -CCONF=gcc.mk - +CCONF=clang.mk +PLATFORM=osx.mk fi echo " diff -r f5102a892ed4 -r 4a10bc0ee80d make/clang.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/clang.mk Thu Jun 20 13:27:07 2013 +0200 @@ -0,0 +1,34 @@ +# +# 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 = -g + +CC = cc +CXX = c++ +LD = cc + diff -r f5102a892ed4 -r 4a10bc0ee80d make/linux.mk --- a/make/linux.mk Mon May 27 12:28:56 2013 +0200 +++ b/make/linux.mk Thu Jun 20 13:27:07 2013 +0200 @@ -29,7 +29,7 @@ # compiler and linker flags CFLAGS += -DLINUX -LDFLAGS = -lpthread -ldl -lnsl -lm -lxerces-c -lldap +LDFLAGS += -lpthread -ldl -lnsl -lm -lxerces-c -lldap # platform dependend source files diff -r f5102a892ed4 -r 4a10bc0ee80d make/osx.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/osx.mk Thu Jun 20 13:27:07 2013 +0200 @@ -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. +# + + +# compiler and linker flags +CFLAGS += -DBSD -DOSX +LDFLAGS += -lpthread -ldl -lm -lxerces-c -lldap + + +# platform dependend source files +PLATFORM_DAEMONOBJ = event_bsd.o + + diff -r f5102a892ed4 -r 4a10bc0ee80d make/suncc.mk --- a/make/suncc.mk Mon May 27 12:28:56 2013 +0200 +++ b/make/suncc.mk Thu Jun 20 13:27:07 2013 +0200 @@ -27,7 +27,6 @@ # CFLAGS += -xc99 -g -D_REENTRANT -LDFLAGS += -lpthread -ldl -lm -lxerces-c -lldap CC = cc CXX = CC diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/daemon/acl.c --- a/src/server/daemon/acl.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/daemon/acl.c Thu Jun 20 13:27:07 2013 +0200 @@ -546,3 +546,14 @@ #endif +/* + * generic code for all non acl unices + * TODO: don't use OSX in the preprocessor directive + */ +#ifdef OSX + +int fs_acl_check(SysACL *acl, User *user, char *path, uint32_t access_mask) { + return 1; +} + +#endif diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/daemon/configmanager.c --- a/src/server/daemon/configmanager.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/daemon/configmanager.c Thu Jun 20 13:27:07 2013 +0200 @@ -105,7 +105,7 @@ } //printf("1 time: %d - %d\n", f->last_modified, s.st_mtim.tv_sec); - if(f->last_modified != s.st_mtim.tv_sec) { + if(f->last_modified != s.st_mtime) { /* reload the file */ printf("reload: %s\n", f->file.ptr); log_ereport( @@ -113,7 +113,7 @@ "reload configuration file: %s", f->file.ptr); f->reload(f, conf); - f->last_modified = s.st_mtim.tv_sec; + f->last_modified = s.st_mtime; if(reload) { *reload = 1; } @@ -152,7 +152,7 @@ return -1; } - sc_last_modified = s.st_mtim.tv_sec; + sc_last_modified = s.st_mtime; } else if(0) { /* copy configuration */ printf("cfgmgr copy server.conf\n"); diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/daemon/event_bsd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/daemon/event_bsd.c Thu Jun 20 13:27:07 2013 +0200 @@ -0,0 +1,105 @@ +/* + * 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. + */ + +#include +#include + +#include "event_bsd.h" + +event_handler_t* evhandler_create(int numthreads) { + event_handler_t *ev = malloc(sizeof(event_handler_t)); + if(ev == NULL) { + return NULL; + } + + ev->ports = calloc(numthreads, sizeof(int)); + if(ev->ports == NULL) { + free(ev); + return NULL; + } + ev->nports = numthreads; + ev->lp = 0; + + /* create ports event threads */ + for(int i=0;iports[i] = port_create(); + ev->ports[i] = kqueue(); + if(ev->ports[i] == 0) { + free(ev->ports); + free(ev); + return NULL; + } + + /* + * start a new handler thread + * the thread needs the event port and a pointer to the event handler + */ + ev_thr_conf_t *conf = malloc(sizeof(ev_thr_conf_t)); + if(conf == NULL) { + free(ev->ports); + free(ev); + return NULL; + } + conf->handler = ev; + conf->port = ev->ports[i]; + + ev_thr_conf_t *thrconf = malloc(sizeof(ev_thr_conf_t)); + thrconf->handler = ev; + thrconf->port = ev->ports[i]; + systhread_start(0, 0, (thrstartfunc)ev_handle_events, thrconf); + /* TODO: error handling */ + } + + return ev; +} + +void ev_handle_events(ev_thr_conf_t *conf) { + +} + +/* returns a event handler port */ +int ev_get_port(event_handler_t *h) { + +} + +int ev_pollin(event_handler_t *h, int fd, event_t *event) { + +} + +int ev_pollout(event_handler_t *h, int fd, event_t *event) { + +} + +int ev_poll(event_handler_t *h, event_t *event) { + +} + +int evt_send(event_handler_t *h, event_t *event) { + +} diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/daemon/event_bsd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/server/daemon/event_bsd.h Thu Jun 20 13:27:07 2013 +0200 @@ -0,0 +1,64 @@ +/* + * 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. + */ + +#ifndef EVENT_SOLARIS_H +#define EVENT_SOLARIS_H + +#include "event.h" +#include "../util/systhr.h" + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct event_handler { + int *ports; + uint32_t nports; + uint32_t lp; +}; + +typedef struct ev_thr_conf { + event_handler_t *handler; + int port; +} ev_thr_conf_t; + +void ev_handle_events(ev_thr_conf_t *conf); + +int ev_get_port(event_handler_t *h); + +int ev_poll(event_handler_t *h, event_t *event); + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT_SOLARIS_H */ + diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/daemon/httplistener.c --- a/src/server/daemon/httplistener.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/daemon/httplistener.c Thu Jun 20 13:27:07 2013 +0200 @@ -148,8 +148,8 @@ if(listener->threadpool == NULL) { listener->threadpool = get_default_threadpool(); } - //listener->session_handler = create_basic_session_handler(); - listener->session_handler = create_event_session_handler(); + listener->session_handler = create_basic_session_handler(); + //listener->session_handler = create_event_session_handler(); listener->nacceptors = conf->nacceptors; listener->port = conf->port; listener->ref = 1; diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/daemon/vfs.c --- a/src/server/daemon/vfs.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/daemon/vfs.c Thu Jun 20 13:27:07 2013 +0200 @@ -292,17 +292,8 @@ } } - // open file - int sys_fd = open(path, O_RDONLY); - if(sys_fd == -1) { - if(ctx) { - ctx->vfs_errno = errno; - sys_set_error_status(ctx); - } - return NULL; - } - - DIR *sys_dir = fdopendir(sys_fd); + // open file + DIR *sys_dir = opendir(path); if(!sys_dir) { if(ctx) { ctx->vfs_errno = errno; @@ -319,7 +310,7 @@ } dir->ctx = ctx; dir->data = sys_dir; - dir->fd = sys_fd; + dir->fd = dirfd(dir); dir->io = &sys_dir_io; return dir; } @@ -466,6 +457,11 @@ return sys_dir_read(dir, entry, getstat); } else { entry->name = name; +#ifndef OSX + /* TODO: + * implement alternative for fstat for OS X and other crappy + * Unices + */ if(getstat) { // TODO: check ACLs again for new path if(fstatat(dir->fd, e->d_name, &entry->stat, 0)) { @@ -473,6 +469,7 @@ } entry->stat_extra = NULL; } +#endif return 1; } } else { diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/safs/pathcheck.c --- a/src/server/safs/pathcheck.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/safs/pathcheck.c Thu Jun 20 13:27:07 2013 +0200 @@ -69,6 +69,8 @@ sstr_t right = rights[i]; access_mask = access_mask | accstr2int(right); } + + return REQ_PROCEED; } int append_acl(pblock *pb, Session *sn, Request *rq) { diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/safs/service.c --- a/src/server/safs/service.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/safs/service.c Thu Jun 20 13:27:07 2013 +0200 @@ -36,7 +36,7 @@ #include "../daemon/protocol.h" #include "../daemon/vfs.h" -#include +//include #include "../util/strbuf.h" #include diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/util/atomic.h --- a/src/server/util/atomic.h Mon May 27 12:28:56 2013 +0200 +++ b/src/server/util/atomic.h Thu Jun 20 13:27:07 2013 +0200 @@ -40,6 +40,13 @@ #define ws_atomic_add32(intptr, val) __sync_fetch_and_add(intptr, val) #define ws_atomic_sub32(intptr, val) __sync_fetch_and_sub(intptr, val) +#elif defined(OSX) +#include + +#define ws_atomic_inc32(intptr) OSAtomicIncrement32((volatile int32_t *)intptr) +#define ws_atomic_dec32(intptr) OSAtomicDecrement32((volatile int32_t *)intptr) + + #else // use atomic.h #include diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/util/io.c --- a/src/server/util/io.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/util/io.c Thu Jun 20 13:27:07 2013 +0200 @@ -33,7 +33,10 @@ #include #include #include +#include +#ifndef BSD #include +#endif #include /* asprintf */ #include "../daemon/vfs.h" @@ -134,7 +137,23 @@ ssize_t ret = 0; off_t fileoffset = sfd->offset; if(sfd->fd->fd != -1) { +#ifdef OSX + struct iovec hdvec; + hdvec.iov_base = (void*)sfd->header; + hdvec.iov_len = sfd->hlen; + struct iovec trvec; + trvec.iov_base = (void*)sfd->trailer; + trvec.iov_len = sfd->tlen; + struct sf_hdtr hdtr; + hdtr.headers = &hdvec; + hdtr.hdr_cnt = 1; + hdtr.trailers = &trvec; + hdtr.trl_cnt = 1; + + ret = sendfile(sfd->fd->fd, st->fd, sfd->offset, (off_t*)&sfd->len, &hdtr, 0); +#else ret = sendfile(st->fd, sfd->fd->fd, &fileoffset, sfd->len); +#endif } else { // TODO: regular copy fprintf(stderr, "sendfile not implemented for SYS_FILE\n"); diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/util/util.c --- a/src/server/util/util.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/util/util.c Thu Jun 20 13:27:07 2013 +0200 @@ -196,7 +196,7 @@ { struct passwd *rv; -#if defined(AIX) || defined(LINUX) || defined(HPUX) +#if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(OSX) errno = getpwnam_r(name, result, buffer, buflen, &rv); if (errno != 0) rv = NULL; @@ -215,7 +215,7 @@ { struct passwd *rv; -#if defined(AIX) || defined(LINUX) || defined(HPUX) +#if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(OSX) errno = getpwuid_r(uid, result, buffer, buflen, &rv); if (errno != 0) rv = NULL; diff -r f5102a892ed4 -r 4a10bc0ee80d src/server/webdav/webdav.c --- a/src/server/webdav/webdav.c Mon May 27 12:28:56 2013 +0200 +++ b/src/server/webdav/webdav.c Thu Jun 20 13:27:07 2013 +0200 @@ -577,11 +577,12 @@ } prop.name = "getlastmodified"; - sstr_t s = date_format_http(st.st_mtim.tv_sec, rq->sn->pool); + + sstr_t s = date_format_http(st.st_mtime, rq->sn->pool); dav_propfind_add_str_prop(rq, &prop, s.ptr, s.length); prop.name = "creationdate"; - s = date_format_iso8601(st.st_ctim.tv_sec, rq->sn->pool); + s = date_format_iso8601(st.st_ctime, rq->sn->pool); dav_propfind_add_str_prop(rq, &prop, s.ptr, s.length); return; @@ -602,10 +603,10 @@ size_t n = snprintf(buf, 32, "%d", st.st_size); dav_propfind_add_str_prop(rq, prop, buf, n); } else if(!strcmp(s, "getlastmodified")) { - sstr_t s = date_format_http(st.st_mtim.tv_sec, rq->sn->pool); + sstr_t s = date_format_http(st.st_mtime, rq->sn->pool); dav_propfind_add_str_prop(rq, prop, s.ptr, s.length); } else if(!strcmp(s, "creationdate")) { - sstr_t s = date_format_iso8601(st.st_ctim.tv_sec, rq->sn->pool); + sstr_t s = date_format_iso8601(st.st_ctime, rq->sn->pool); dav_propfind_add_str_prop(rq, prop, s.ptr, s.length); } else { dav_propfind_add_prop_error(rq, prop, 404);