From: unknown Date: Sun, 20 Apr 2008 17:13:57 +0000 (+0200) Subject: Pazpar2 compiles on Windows. But does not yet work X-Git-Tag: PAZPAR2.1.0.8~11 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=cc178327044177f177d0474b757f53bcd86b4d42;p=pazpar2-moved-to-github.git Pazpar2 compiles on Windows. But does not yet work --- diff --git a/src/client.c b/src/client.c index 696db40..87ef522 100644 --- a/src/client.c +++ b/src/client.c @@ -24,10 +24,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#if HAVE_SYS_TIME_H #include +#endif +#if HAVE_UNISTD_H #include +#endif +#if HAVE_SYS_SOCKET_H #include +#endif +#if HAVE_NETDB_H #include +#endif #include #include #include @@ -55,7 +63,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #endif +#if HAVE_NETINET_IN_H #include +#endif #include "pazpar2.h" diff --git a/src/connection.c b/src/connection.c index 067c7ac..9ea3275 100644 --- a/src/connection.c +++ b/src/connection.c @@ -24,10 +24,23 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#if HAVE_SYS_TIME_H #include +#endif +#if HAVE_UNISTD_H #include +#endif +#if HAVE_SYS_SOCKET_H #include +#endif +#ifdef WIN32 +#include +typedef int socklen_t; +#endif +#if HAVE_NETDB_H #include +#endif + #include #include #include diff --git a/src/database.c b/src/database.c index 30d8a84..347c26b 100644 --- a/src/database.c +++ b/src/database.c @@ -33,9 +33,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "zeerex.h" #include +#if HAVE_SYS_SOCKET_H #include +#endif +#if HAVE_NETDB_H #include +#endif +#if HAVE_NETINET_IN_H #include +#endif static struct host *hosts = 0; // The hosts we know about static struct database *databases = 0; // The databases we know about diff --git a/src/dirent.c b/src/dirent.c new file mode 100644 index 0000000..a0a8a73 --- /dev/null +++ b/src/dirent.c @@ -0,0 +1,86 @@ +/* $Id: dirent.c,v 1.10 2007-01-15 15:10:26 adam Exp $ + Copyright (C) 1995-2007 + Index Data ApS + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + + +#include +#include +#ifdef WIN32 +#include +#endif +#include +#include + +#include "direntz.h" + +#ifdef WIN32 + +struct DIR { + HANDLE handle; + WIN32_FIND_DATA find_data; + struct dirent entry; +}; + +DIR *opendir (const char *name) +{ + char fullName[MAX_PATH+1]; + DIR *dd = malloc (sizeof(*dd)); + + if (!dd) + return NULL; + strcpy (fullName, name); + strcat (fullName, "\\*.*"); + dd->handle = FindFirstFile(fullName, &dd->find_data); + return dd; +} + +struct dirent *readdir (DIR *dd) +{ + if (dd->handle == INVALID_HANDLE_VALUE) + return NULL; + strcpy (dd->entry.d_name, dd->find_data.cFileName); + if (!FindNextFile(dd->handle, &dd->find_data)) + { + FindClose (dd->handle); + dd->handle = INVALID_HANDLE_VALUE; + } + return &dd->entry; +} + +void closedir(DIR *dd) +{ + if (dd->handle != INVALID_HANDLE_VALUE) + FindClose (dd->handle); + if (dd) + free (dd); +} + +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/direntz.h b/src/direntz.h new file mode 100644 index 0000000..a465796 --- /dev/null +++ b/src/direntz.h @@ -0,0 +1,56 @@ +/* $Id: direntz.h,v 1.14 2007-01-15 20:08:24 adam Exp $ + Copyright (C) 1995-2007 + Index Data ApS + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#ifdef WIN32 +/* make WIN32 version of dirent */ +#include + +#include + +YAZ_BEGIN_CDECL + +struct dirent { + char d_name[MAX_PATH]; +}; + +typedef struct DIR DIR; + +DIR *opendir (const char *path); +struct dirent *readdir (DIR *dd); +void closedir (DIR *dd); + +YAZ_END_CDECL + +#else +/* include UNIX version */ +#include +#include +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/eventl.c b/src/eventl.c index 7cbd6b0..29a621c 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -40,7 +40,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #else #include #endif +#if HAVE_SYS_TIME_H #include +#endif + #include #include #include diff --git a/src/getaddrinfo.c b/src/getaddrinfo.c index 0e9a96a..63586c7 100644 --- a/src/getaddrinfo.c +++ b/src/getaddrinfo.c @@ -23,14 +23,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "sel_thread.h" +#if HAVE_UNISTD_H #include +#endif #include -#include + #include #include +#if HAVE_SYS_SOCKET_H #include +#endif +#ifdef WIN32 +#include +#endif +#if HAVE_NETDB_H #include +#endif +#if HAVE_NETINET_IN_H #include +#endif #include #include @@ -122,11 +133,14 @@ static void work_handler(void *vp) if (sec) { yaz_log(log_level, "waiting %d seconds", sec); +#if HAVE_UNISTD_H sleep(sec); +#endif } perform_getaddrinfo(w); } +#ifndef WIN32 void iochan_handler(struct iochan *i, int event) { sel_thread_t p = iochan_getdata(i); @@ -162,6 +176,7 @@ static void getaddrinfo_start(void) yaz_log(log_level, "resolver start"); resolver_thread = p; } +#endif int host_getaddrinfo(struct host *host) { @@ -171,21 +186,21 @@ int host_getaddrinfo(struct host *host) w->hostport = host->hostport; w->ipport = 0; w->host = host; +#ifndef WIN32 if (use_thread) { if (resolver_thread == 0) getaddrinfo_start(); assert(resolver_thread); sel_thread_add(resolver_thread, w); + return 0; } - else - { - perform_getaddrinfo(w); - host->ipport = w->ipport; - xfree(w); - if (!host->ipport) - return -1; - } +#endif + perform_getaddrinfo(w); + host->ipport = w->ipport; + xfree(w); + if (!host->ipport) + return -1; return 0; } diff --git a/src/http.c b/src/http.c index f4d8d69..b1d7b43 100644 --- a/src/http.c +++ b/src/http.c @@ -18,16 +18,33 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include +#ifdef WIN32 +#include +typedef int socklen_t; +#endif + +#if HAVE_SYS_SOCKET_H #include +#endif + #include +#if HAVE_SYS_UIO_H #include +#endif + #include +#if HAVE_UNISTD_H #include +#endif + #include -#include +#include #include #include +#if HAVE_NETDB_H #include +#endif + #include #include #include @@ -36,9 +53,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #endif +#if HAVE_NETINET_IN_H #include +#endif + +#if HAVE_ARPA_INET_H #include -#include +#endif #include #include @@ -679,7 +700,33 @@ struct http_header * http_header_append(struct http_channel *ch, return hp; } - + +static int is_inprogress(void) +{ +#ifdef WIN32 + if (WSAGetLastError() != WSAEWOULDBLOCK) + return 1; +#else + if (errno != EINPROGRESS) + return 1; +#endif + return 0; +} + +static void enable_nonblock(int sock) +{ + int flags; +#ifdef WIN32 + flags = (flags & CS_FLAGS_BLOCKING) ? 0 : 1; + if (ioctlsocket(sock, FIONBIO, &flags) < 0) + yaz_log(YLOG_FATAL|YLOG_ERRNO, "ioctlsocket"); +#else + if ((flags = fcntl(sock, F_GETFL, 0)) < 0) + yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl"); + if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) + yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2"); +#endif +} static int http_proxy(struct http_request *rq) { @@ -696,7 +743,6 @@ static int http_proxy(struct http_request *rq) int sock; struct protoent *pe; int one = 1; - int flags; if (!(pe = getprotobyname("tcp"))) { abort(); @@ -709,18 +755,16 @@ static int http_proxy(struct http_request *rq) if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*) &one, sizeof(one)) < 0) abort(); - if ((flags = fcntl(sock, F_GETFL, 0)) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl"); - if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2"); + enable_nonblock(sock); if (connect(sock, (struct sockaddr *) proxy_addr, sizeof(*proxy_addr)) < 0) - if (errno != EINPROGRESS) + { + if (!is_inprogress()) { yaz_log(YLOG_WARN|YLOG_ERRNO, "Proxy connect"); return -1; } - + } p = xmalloc(sizeof(struct http_proxy)); p->oqueue = 0; p->channel = c; @@ -810,7 +854,7 @@ static void http_io(IOCHAN i, int event) case EVENT_INPUT: htbuf = http_buf_create(); - res = read(iochan_getfd(i), htbuf->buf, HTTP_BUF_SIZE -1); + res = recv(iochan_getfd(i), htbuf->buf, HTTP_BUF_SIZE -1, 0); if (res == -1 && errno == EAGAIN) { http_buf_destroy(htbuf); @@ -860,7 +904,7 @@ static void http_io(IOCHAN i, int event) if (hc->oqueue) { struct http_buf *wb = hc->oqueue; - res = write(iochan_getfd(hc->iochan), wb->buf + wb->offset, wb->len); + res = send(iochan_getfd(hc->iochan), wb->buf + wb->offset, wb->len, 0); if (res <= 0) { yaz_log(YLOG_WARN|YLOG_ERRNO, "write"); @@ -914,15 +958,19 @@ static void proxy_io(IOCHAN pi, int event) case EVENT_INPUT: htbuf = http_buf_create(); - res = read(iochan_getfd(pi), htbuf->buf, HTTP_BUF_SIZE -1); - if (res == 0 || (res < 0 && errno != EINPROGRESS)) + res = recv(iochan_getfd(pi), htbuf->buf, HTTP_BUF_SIZE -1, 0); + if (res == 0 || (res < 0 && !is_inprogress())) { if (hc->oqueue) { yaz_log(YLOG_WARN, "Proxy read came up short"); // Close channel and alert client HTTP channel that we're gone http_buf_destroy(htbuf); +#ifdef WIN32 + closesocket(iochan_getfd(pi)); +#else close(iochan_getfd(pi)); +#endif iochan_destroy(pi); pc->iochan = 0; } @@ -949,7 +997,7 @@ static void proxy_io(IOCHAN pi, int event) iochan_clearflag(pi, EVENT_OUTPUT); return; } - res = write(iochan_getfd(pi), htbuf->buf + htbuf->offset, htbuf->len); + res = send(iochan_getfd(pi), htbuf->buf + htbuf->offset, htbuf->len, 0); if (res <= 0) { yaz_log(YLOG_WARN|YLOG_ERRNO, "write"); @@ -957,7 +1005,7 @@ static void proxy_io(IOCHAN pi, int event) return; } if (res == htbuf->len) - { + { struct http_buf *np = htbuf->next; http_buf_destroy(htbuf); pc->oqueue = np; @@ -990,7 +1038,11 @@ static void http_destroy(IOCHAN i) { if (s->proxy->iochan) { +#ifdef WIN32 + closesocket(iochan_getfd(s->proxy->iochan)); +#else close(iochan_getfd(s->proxy->iochan)); +#endif iochan_destroy(s->proxy->iochan); } http_buf_destroy_queue(s->proxy->oqueue); @@ -1002,7 +1054,11 @@ static void http_destroy(IOCHAN i) http_destroy_observers(s); s->next = http_channel_freelist; http_channel_freelist = s; +#ifdef WIN32 + closesocket(iochan_getfd(i)); +#else close(iochan_getfd(i)); +#endif iochan_destroy(i); } @@ -1048,7 +1104,6 @@ static void http_accept(IOCHAN i, int event) socklen_t len; int s; IOCHAN c; - int flags; struct http_channel *ch; len = sizeof addr; @@ -1057,10 +1112,7 @@ static void http_accept(IOCHAN i, int event) yaz_log(YLOG_WARN|YLOG_ERRNO, "accept"); return; } - if ((flags = fcntl(s, F_GETFL, 0)) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl"); - if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2"); + enable_nonblock(s); yaz_log(YLOG_DEBUG, "New command connection"); c = iochan_create(s, http_io, EVENT_INPUT | EVENT_EXCEPT); @@ -1081,7 +1133,7 @@ void http_init(const char *addr) struct sockaddr_in myaddr; int one = 1; const char *pp; - int port; + short port; yaz_log(YLOG_LOG, "HTTP listener %s", addr); @@ -1139,7 +1191,7 @@ void http_init(const char *addr) void http_set_proxyaddr(char *host, char *base_url) { char *p; - int port; + short port; struct hostent *he; strcpy(myurl, base_url); diff --git a/src/http_command.c b/src/http_command.c index 24928d9..0de007b 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -23,12 +23,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#if HAVE_SYS_UIO_H #include +#endif +#if HAVE_UNISTD_H #include +#endif #include -#include +#include #include +#if HAVE_SYS_TIME_H #include +#endif #include #if HAVE_CONFIG_H #include @@ -166,6 +172,9 @@ unsigned int make_sessionid() res = seq; else { +#ifdef WIN32 + res = seq; +#else struct timeval t; if (gettimeofday(&t, 0) < 0) @@ -177,6 +186,7 @@ unsigned int make_sessionid() (long long would be more appropriate)*/ res = t.tv_sec; res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1); +#endif } return res; } diff --git a/src/logic.c b/src/logic.c index bf1a9d1..8abdcae 100644 --- a/src/logic.c +++ b/src/logic.c @@ -24,10 +24,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#if HAVE_SYS_TIME_H #include +#endif +#if HAVE_UNISTD_H #include +#endif +#if HAVE_SYS_SOCKET_H #include +#endif +#if HAVE_NETDB_H #include +#endif #include #include #include @@ -55,7 +63,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #endif +#if HAVE_NETINET_IN_H #include +#endif #include "pazpar2.h" #include "eventl.h" diff --git a/src/pazpar2.c b/src/pazpar2.c index 0a32283..a4be363 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -52,7 +52,7 @@ void child_handler(void *data) static void show_version(void) { char yaz_version_str[80]; - printf("Pazpar2 " VERSION "\n"); + printf("Pazpar2 " PACKAGE_VERSION "\n"); yaz_version(yaz_version_str, 0); @@ -74,8 +74,10 @@ int main(int argc, char **argv) const char *pidfile = 0; const char *uid = 0; +#ifndef WIN32 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) yaz_log(YLOG_WARN|YLOG_ERRNO, "signal"); +#endif yaz_log_init_prefix("pazpar2"); #if YAZ_VERSIONL >= 0x03001B diff --git a/src/pazpar2.h b/src/pazpar2.h index 509ad9b..1ce73ca 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -21,8 +21,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define PAZPAR2_H -#include - #include #include diff --git a/src/settings.c b/src/settings.c index 5cb08c1..8dbb687 100644 --- a/src/settings.c +++ b/src/settings.c @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include -#include +#include "direntz.h" #include #include @@ -245,7 +245,7 @@ static void read_settings(const char *path, } closedir(d); } - else if ((dot = rindex(path, '.')) && !strcmp(dot + 1, "xml")) + else if ((dot = strrchr(path, '.')) && !strcmp(dot + 1, "xml")) read_settings_file(path, fun); } diff --git a/src/util.h b/src/util.h index 0aae9e5..3a3e6ce 100644 --- a/src/util.h +++ b/src/util.h @@ -22,4 +22,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA void die(char *string, char *add); +#ifdef WIN32 +#define strncasecmp _strnicmp +#define strcasecmp _stricmp +#endif + #endif