From: Adam Dickmeiss Date: Thu, 23 Nov 2000 10:58:32 +0000 (+0000) Subject: SSL comstack support. Separate POSIX thread support library. X-Git-Tag: YAZ.1.8~163 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=8e4eabe621f8b8195faa6625a38a2e1ae7b68aa1;p=yaz-moved-to-github.git SSL comstack support. Separate POSIX thread support library. --- diff --git a/CHANGELOG b/CHANGELOG index 03724e9..15733f3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,13 +1,23 @@ Possible compatibility problems with earlier versions marked with '*'. +On UNIX when POSIX threads are available, a separate library libyazthread +is created. Programmers should link with that library and the yaz library +when using threads. The reason for the split was that some applications +on Linux, such as Apache, doesn't work well when using shared objects that +relies on threads. + +Added SSL support for the COMSTACK. You start yaz-client and yaz-ztest +(or any frontend server) in SSL mode by specifying ssl: followed by +address. + Added feature for CCL module. Virtual structure s=al or s=ol generates and-list and or-list respectively instead of phrase search. Added some OID's. * Added prefix "yaz_" for the functions log_init.., log_file.. and -log_mask_str. This was done to avoid name conflicts with other -libraries (say other PHP extensions). +log_mask_str. This was done to avoid name conflicts with other libraries +(such as other PHP extensions). Added raw OID member for preferred record syntax (request_format_raw) and returned record syntax (output_format_raw) for backend fetch method. diff --git a/Makefile.in b/Makefile.in index 3cfe830..abd6039 100644 --- a/Makefile.in +++ b/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ @@ -151,6 +152,8 @@ uninstall-aclocalDATA: # (which will cause the Makefiles to be regenerated when you run `make'); # (2) otherwise, pass the desired values on the `make' command line. +@SET_MAKE@ + all-recursive install-data-recursive install-exec-recursive \ installdirs-recursive install-recursive uninstall-recursive \ check-recursive installcheck-recursive info-recursive dvi-recursive: @@ -177,11 +180,10 @@ maintainer-clean-recursive: @set fnord $(MAKEFLAGS); amf=$$2; \ dot_seen=no; \ rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = "."; then :; else \ - rev="$$subdir $$rev"; \ - fi; \ + rev="$$subdir $$rev"; \ + test "$$subdir" = "." && dot_seen=yes; \ done; \ - rev="$$rev ."; \ + test "$$dot_seen" = "no" && rev=". $$rev"; \ target=`echo $@ | sed s/-recursive//`; \ for subdir in $$rev; do \ echo "Making $$target in $$subdir"; \ diff --git a/README b/README index b706158..54241d1 100644 --- a/README +++ b/README @@ -3,11 +3,11 @@ Copyright (C) 1995-2000, Index Data ApS. See the file LICENSE for details. Compilation and installation instructions for YAZ - $Id: README,v 1.31 2000-04-05 07:39:54 adam Exp $ + $Id: README,v 1.32 2000-11-23 10:58:32 adam Exp $ The primary output of the source here is the lib/libyaz.a library, which contains support functions for implementing the server or client -role of Z39.50/SR. +role of Z39.50. Windows programmers: refer to the file windows.txt which describes how to build the software using Microsoft Visual C++. diff --git a/aclocal.m4 b/aclocal.m4 index 9bd619b..da8cc99 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -513,3 +513,16 @@ AC_DEFUN(AM_PROG_NM, [indir([AC_PROG_NM])])dnl dnl This is just to silence aclocal about the macro not being used ifelse([AC_DISABLE_FAST_INSTALL])dnl +# Define a conditional. + +AC_DEFUN(AM_CONDITIONAL, +[AC_SUBST($1_TRUE) +AC_SUBST($1_FALSE) +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi]) + diff --git a/asn/Makefile.in b/asn/Makefile.in index 6b3a2df..e797041 100644 --- a/asn/Makefile.in +++ b/asn/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/ccl/Makefile.in b/ccl/Makefile.in index 82debb6..c877ebf 100644 --- a/ccl/Makefile.in +++ b/ccl/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/client/Makefile.in b/client/Makefile.in index 745fe64..d5e3f02 100644 --- a/client/Makefile.in +++ b/client/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/client/client.c b/client/client.c index c23dcfe..4ff4a15 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.107 2000-11-16 13:11:07 adam + * Revision 1.108 2000-11-23 10:58:32 adam + * SSL comstack support. Separate POSIX thread support library. + * + * Revision 1.107 2000/11/16 13:11:07 adam * Changed because ccl_rpn_query sets attribute set. * * Revision 1.106 2000/11/13 09:44:59 adam @@ -588,16 +591,25 @@ int cmd_open(char *arg) session_mem = NULL; } } + t = tcpip_type; base[0] = '\0'; if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1) return 0; if (strncmp (type_and_host, "tcp:", 4) == 0) host = type_and_host + 4; + else if (strncmp (type_and_host, "ssl:", 4) == 0) + { +#if HAVE_OPENSSL_SSL_H + t = ssl_type; +#else + printf ("SSL not supported\n"); +#endif + host = type_and_host + 4; + } else host = type_and_host; if (*base) cmd_base (base); - t = tcpip_type; protocol = PROTO_Z3950; if (!(conn = cs_create(t, 1, protocol))) diff --git a/comstack/Makefile.in b/comstack/Makefile.in index 617bfaa..119b29a 100644 --- a/comstack/Makefile.in +++ b/comstack/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/comstack/tcpip.c b/comstack/tcpip.c index dd9e03b..c6076b0 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: tcpip.c,v $ - * Revision 1.33 2000-09-04 08:27:11 adam + * Revision 1.34 2000-11-23 10:58:32 adam + * SSL comstack support. Separate POSIX thread support library. + * + * Revision 1.33 2000/09/04 08:27:11 adam * Work on error handling for tcpip_accept. * * Revision 1.32 1999/11/30 13:47:11 adam @@ -183,6 +186,10 @@ #endif #include #include +#if HAVE_OPENSSL_SSL_H +#include +#include +#endif #include #include @@ -202,17 +209,22 @@ int tcpip_listen(COMSTACK h, char *raddr, int *addrlen, int (*check_ip)(void *cd, const char *a, int len, int type), void *cd); +#if HAVE_OPENSSL_SSL_H +int ssl_get(COMSTACK h, char **buf, int *bufsize); +int ssl_put(COMSTACK h, char *buf, int size); +#endif + COMSTACK tcpip_accept(COMSTACK h); char *tcpip_addrstr(COMSTACK h); void *tcpip_straddr(COMSTACK h, const char *str); -#undef TRACE_TCPIP -#ifdef TRACE_TCPIP +#if 0 #define TRC(x) x #else #define TRC(X) #endif +/* this state is used for both SSL and straight TCP/IP */ typedef struct tcpip_state { char *altbuf; /* alternate buffer for surplus data */ @@ -224,6 +236,11 @@ typedef struct tcpip_state int (*complete)(const unsigned char *buf, int len); /* length/comple. */ struct sockaddr_in addr; /* returned by cs_straddr */ char buf[128]; /* returned by cs_addrstr */ +#if HAVE_OPENSSL_SSL_H + SSL_CTX *ctx; + SSL_CTX *ctx_alloc; + SSL *ssl; +#endif } tcpip_state; #ifdef WIN32 @@ -243,7 +260,6 @@ static int tcpip_init (void) return 1; } #else - static int proto_number = 0; static int tcpip_init (void) @@ -256,11 +272,12 @@ static int tcpip_init (void) return 1; } #endif + /* * This function is always called through the cs_create() macro. * s >= 0: socket has already been established for us. */ -COMSTACK tcpip_type(int s, int blocking, int protocol) +COMSTACK tcpip_type(int s, int blocking, int protocol, void *vp) { COMSTACK p; tcpip_state *state; @@ -297,6 +314,7 @@ COMSTACK tcpip_type(int s, int blocking, int protocol) #endif return 0; + p->io_pending = 0; p->iofile = s; p->type = tcpip_type; p->protocol = (enum oid_proto) protocol; @@ -318,6 +336,11 @@ COMSTACK tcpip_type(int s, int blocking, int protocol) p->cerrno = 0; p->stackerr = 0; +#if HAVE_OPENSSL_SSL_H + state->ctx = state->ctx_alloc = 0; + state->ssl = 0; +#endif + state->altbuf = 0; state->altsize = state->altlen = 0; state->towrite = state->written = -1; @@ -332,6 +355,41 @@ COMSTACK tcpip_type(int s, int blocking, int protocol) return p; } +#if HAVE_OPENSSL_SSL_H + +COMSTACK ssl_type(int s, int blocking, int protocol, void *vp) +{ + tcpip_state *state; + COMSTACK p; + yaz_log(LOG_LOG, "ssl_type begin"); + + p = tcpip_type (s, blocking, protocol, 0); + if (!p) + return 0; + p->f_get = ssl_get; + p->f_put = ssl_put; + p->type = ssl_type; + state = (tcpip_state *) p->cprivate; + if (vp) + state->ctx = vp; + else + { + SSL_load_error_strings(); + OpenSSL_add_all_algorithms(); + + state->ctx = state->ctx_alloc = SSL_CTX_new (SSLv23_method()); + if (!state->ctx) + { + tcpip_close(p); + return 0; + } + } + /* note: we don't handle already opened socket in SSL mode - yet */ + yaz_log(LOG_LOG, "ssl_type end"); + return p; +} +#endif + int tcpip_strtoaddr_ex(const char *str, struct sockaddr_in *add) { struct hostent *hp; @@ -399,18 +457,72 @@ int tcpip_more(COMSTACK h) int tcpip_connect(COMSTACK h, void *address) { struct sockaddr_in *add = (struct sockaddr_in *)address; +#if HAVE_OPENSSL_SSL_H + tcpip_state *sp = (tcpip_state *)h->cprivate; +#endif + int r; TRC(fprintf(stderr, "tcpip_connect\n")); - if (connect(h->iofile, (struct sockaddr *) add, sizeof(*add)) < 0) + h->io_pending = 0; + if (h->state == CS_UNBND) { + r = connect(h->iofile, (struct sockaddr *) add, sizeof(*add)); + if (r < 0) + { #ifdef WIN32 - if (WSAGetLastError() == WSAEWOULDBLOCK) + if (WSAGetLastError() == WSAEWOULDBLOCK) + { + h->state = CS_CONNECTING; + h->io_pending = CS_WANT_WRITE; + return 1; + } #else - if (errno == EINPROGRESS) + if (errno == EINPROGRESS) + { + h->state = CS_CONNECTING; + h->io_pending = CS_WANT_WRITE|CS_WANT_READ; + return 1; + } #endif - return 1; - return -1; + return -1; + } + h->state = CS_CONNECTING; + } + if (h->state != CS_CONNECTING) + { + h->cerrno = CSOUTSTATE; + return -1; + } +#if HAVE_OPENSSL_SSL_H + if (sp->ctx) + { + int res; + + if (!sp->ssl) + { + sp->ssl = SSL_new (sp->ctx); + SSL_set_fd (sp->ssl, h->iofile); + } + res = SSL_connect (sp->ssl); + if (res <= 0) + { + int err = SSL_get_error(sp->ssl, res); + if (err == SSL_ERROR_WANT_READ) + { + yaz_log (LOG_LOG, "SSL_connect. want_read"); + h->io_pending = CS_WANT_READ; + return 1; + } + if (err == SSL_ERROR_WANT_WRITE) + { + yaz_log (LOG_LOG, "SSL_connect. want_write"); + h->io_pending = CS_WANT_WRITE; + return 1; + } + return -1; + } } +#endif h->state = CS_DATAXFER; return 0; } @@ -424,6 +536,9 @@ int tcpip_rcvconnect(COMSTACK h) return 0; } +#define CERTF "ztest.pem" +#define KEYF "ztest.pem" + int tcpip_bind(COMSTACK h, void *address, int mode) { struct sockaddr *addr = (struct sockaddr *)address; @@ -433,7 +548,43 @@ int tcpip_bind(COMSTACK h, void *address, int mode) unsigned long one = 1; #endif - TRC(fprintf(stderr, "tcpip_bind\n")); +#if HAVE_OPENSSL_SSL_H + tcpip_state *sp = (tcpip_state *)h->cprivate; + if (sp->ctx) + { + if (sp->ctx_alloc) + { + int res; + res = SSL_CTX_use_certificate_file (sp->ctx, CERTF, + SSL_FILETYPE_PEM); + if (res <= 0) + { + ERR_print_errors_fp(stderr); + exit (2); + } + res = SSL_CTX_use_PrivateKey_file (sp->ctx, KEYF, + SSL_FILETYPE_PEM); + if (res <= 0) + { + ERR_print_errors_fp(stderr); + exit (3); + } + res = SSL_CTX_check_private_key (sp->ctx); + if (res <= 0) + { + ERR_print_errors_fp(stderr); + exit(5); + } + } + TRC (fprintf (stderr, "ssl_bind\n")); + } + else + { + TRC (fprintf (stderr, "tcpip_bind\n")); + } +#else + TRC (fprintf (stderr, "tcpip_bind\n")); +#endif if (setsockopt(h->iofile, SOL_SOCKET, SO_REUSEADDR, (char*) &one, sizeof(one)) < 0) { @@ -511,67 +662,116 @@ COMSTACK tcpip_accept(COMSTACK h) #endif TRC(fprintf(stderr, "tcpip_accept\n")); - if (h->state != CS_INCON) - { - h->cerrno = CSOUTSTATE; - return 0; - } - if (!(cnew = (COMSTACK)xmalloc(sizeof(*cnew)))) - { - h->cerrno = CSYSERR; -#ifdef WIN32 - closesocket(h->newfd); -#else - close(h->newfd); -#endif - h->newfd = -1; - return 0; - } - memcpy(cnew, h, sizeof(*h)); - cnew->iofile = h->newfd; - if (!(state = (tcpip_state *) - (cnew->cprivate = xmalloc(sizeof(tcpip_state))))) + if (h->state == CS_INCON) { - h->cerrno = CSYSERR; - if (h->newfd != -1) + if (!(cnew = (COMSTACK)xmalloc(sizeof(*cnew)))) { + h->cerrno = CSYSERR; #ifdef WIN32 closesocket(h->newfd); #else close(h->newfd); #endif h->newfd = -1; + return 0; } - return 0; - } + memcpy(cnew, h, sizeof(*h)); + cnew->iofile = h->newfd; + cnew->io_pending = 0; + if (!(state = (tcpip_state *) + (cnew->cprivate = xmalloc(sizeof(tcpip_state))))) + { + h->cerrno = CSYSERR; + if (h->newfd != -1) + { #ifdef WIN32 - if (!cnew->blocking && ioctlsocket(cnew->iofile, FIONBIO, &tru) < 0) + closesocket(h->newfd); #else - if (!cnew->blocking && fcntl(cnew->iofile, F_SETFL, O_NONBLOCK) < 0) + close(h->newfd); #endif - { - h->cerrno = CSYSERR; - if (h->newfd != -1) + h->newfd = -1; + } + return 0; + } + if (!cnew->blocking && +#ifdef WIN32 + (ioctlsocket(cnew->iofile, FIONBIO, &tru) < 0) +#else + (!cnew->blocking && fcntl(cnew->iofile, F_SETFL, O_NONBLOCK) < 0) +#endif + ) { + h->cerrno = CSYSERR; + if (h->newfd != -1) + { #ifdef WIN32 - closesocket(h->newfd); + closesocket(h->newfd); #else - close(h->newfd); + close(h->newfd); #endif - h->newfd = -1; + h->newfd = -1; + } + xfree (cnew); + xfree (state); + return 0; + } + h->newfd = -1; + state->altbuf = 0; + state->altsize = state->altlen = 0; + state->towrite = state->written = -1; + state->complete = st->complete; + cnew->state = CS_ACCEPT; + h->state = CS_IDLE; + +#if HAVE_OPENSSL_SSL_H + state->ctx = st->ctx; + state->ctx_alloc = 0; + state->ssl = st->ssl; + if (state->ctx) + { + state->ssl = SSL_new (state->ctx); + SSL_set_fd (state->ssl, cnew->iofile); } - xfree (cnew); - xfree (state); +#endif + h = cnew; + } + if (h->state == CS_ACCEPT) + { +#if HAVE_OPENSSL_SSL_H + tcpip_state *state = (tcpip_state *)h->cprivate; + if (state->ctx) + { + int res = SSL_accept (state->ssl); + TRC(fprintf(stderr, "SSL_accept\n")); + if (res <= 0) + { + int err = SSL_get_error(state->ssl, res); + if (err == SSL_ERROR_WANT_READ) + { + h->io_pending = CS_WANT_READ; + yaz_log (LOG_LOG, "SSL_accept. want_read"); + return h; + } + if (err == SSL_ERROR_WANT_WRITE) + { + h->io_pending = CS_WANT_WRITE; + yaz_log (LOG_LOG, "SSL_accept. want_write"); + return h; + } + cs_close (h); + return 0; + } + } +#endif + } + else + { + h->cerrno = CSOUTSTATE; return 0; } - h->newfd = -1; - state->altbuf = 0; - state->altsize = state->altlen = 0; - state->towrite = state->written = -1; - state->complete = st->complete; - cnew->state = CS_DATAXFER; - h->state = CS_IDLE; - return cnew; + h->io_pending = 0; + h->state = CS_DATAXFER; + return h; } #define CS_TCPIP_BUFCHUNK 4096 @@ -601,6 +801,7 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) sp->altbuf = tmpc; sp->altsize = tmpi; } + h->io_pending = 0; while (!(berlen = (*sp->complete)((unsigned char *)*buf, hasread))) { if (!*bufsize) @@ -611,11 +812,16 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) else if (*bufsize - hasread < CS_TCPIP_BUFCHUNK) if (!(*buf =(char *)xrealloc(*buf, *bufsize *= 2))) return -1; - if ((res = recv(h->iofile, *buf + hasread, CS_TCPIP_BUFCHUNK, 0)) < 0) + res = recv(h->iofile, *buf + hasread, CS_TCPIP_BUFCHUNK, 0); + TRC(fprintf(stderr, " recv res=%d, hasread=%d\n", res, hasread)); + if (res < 0) { #ifdef WIN32 - if (WSAGetLastError() == WSAEWOULDBLOCK) + if (WSAGetLastError() == WSAEWOULDBLOCK) + { + h->io_pending = CS_WANT_READ; break; + } else return -1; #else @@ -624,19 +830,107 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) || errno == EINPROGRESS #endif ) + { + h->io_pending = CS_WANT_READ; break; - else if (errno == 0) + } + else if (errno == 0) continue; else - return -1; + return -1; #endif } - if (!res) - return 0; + else if (!res) + return 0; hasread += res; - TRC(fprintf(stderr, " res=%d, hasread=%d\n", res, hasread)); } - TRC(fprintf(stderr, " Out of read loop with hasread=%d, berlen=%d\n", + TRC (fprintf (stderr, " Out of read loop with hasread=%d, berlen=%d\n", + hasread, berlen)); + /* move surplus buffer (or everything if we didn't get a BER rec.) */ + if (hasread > berlen) + { + tomove = req = hasread - berlen; + rest = tomove % CS_TCPIP_BUFCHUNK; + if (rest) + req += CS_TCPIP_BUFCHUNK - rest; + if (!sp->altbuf) + { + if (!(sp->altbuf = (char *)xmalloc(sp->altsize = req))) + return -1; + } else if (sp->altsize < req) + if (!(sp->altbuf =(char *)xrealloc(sp->altbuf, sp->altsize = req))) + return -1; + TRC(fprintf(stderr, " Moving %d bytes to altbuf(0x%x)\n", tomove, + (unsigned) sp->altbuf)); + memcpy(sp->altbuf, *buf + berlen, sp->altlen = tomove); + } + if (berlen < CS_TCPIP_BUFCHUNK - 1) + *(*buf + berlen) = '\0'; + return berlen ? berlen : 1; +} + + +#if HAVE_OPENSSL_SSL_H +/* + * Return: -1 error, >1 good, len of buffer, ==1 incomplete buffer, + * 0=connection closed. + */ +int ssl_get(COMSTACK h, char **buf, int *bufsize) +{ + tcpip_state *sp = (tcpip_state *)h->cprivate; + char *tmpc; + int tmpi, berlen, rest, req, tomove; + int hasread = 0, res; + + TRC(fprintf(stderr, "ssl_get: bufsize=%d\n", *bufsize)); + if (sp->altlen) /* switch buffers */ + { + TRC(fprintf(stderr, " %d bytes in altbuf (0x%x)\n", sp->altlen, + (unsigned) sp->altbuf)); + tmpc = *buf; + tmpi = *bufsize; + *buf = sp->altbuf; + *bufsize = sp->altsize; + hasread = sp->altlen; + sp->altlen = 0; + sp->altbuf = tmpc; + sp->altsize = tmpi; + } + h->io_pending = 0; + while (!(berlen = (*sp->complete)((unsigned char *)*buf, hasread))) + { + if (!*bufsize) + { + if (!(*buf = (char *)xmalloc(*bufsize = CS_TCPIP_BUFCHUNK))) + return -1; + } + else if (*bufsize - hasread < CS_TCPIP_BUFCHUNK) + if (!(*buf =(char *)xrealloc(*buf, *bufsize *= 2))) + return -1; + res = SSL_read (sp->ssl, *buf + hasread, CS_TCPIP_BUFCHUNK); + TRC(fprintf(stderr, " SSL_read res=%d, hasread=%d\n", res, hasread)); + if (res <= 0) + { + int ssl_err = SSL_get_error(sp->ssl, res); + if (ssl_err == SSL_ERROR_WANT_READ) + { + h->io_pending = CS_WANT_READ; + yaz_log (LOG_LOG, "SSL_read. want_read"); + break; + } + if (ssl_err == SSL_ERROR_WANT_WRITE) + { + h->io_pending = CS_WANT_WRITE; + yaz_log (LOG_LOG, "SSL_read. want_write"); + break; + } + if (res == 0) + return 0; + return -1; + } + hasread += res; + } + TRC (fprintf (stderr, " Out of read loop with hasread=%d, berlen=%d\n", hasread, berlen)); /* move surplus buffer (or everything if we didn't get a BER rec.) */ if (hasread > berlen) @@ -660,6 +954,7 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) *(*buf + berlen) = '\0'; return berlen ? berlen : 1; } +#endif /* * Returns 1, 0 or -1 @@ -672,6 +967,7 @@ int tcpip_put(COMSTACK h, char *buf, int size) struct tcpip_state *state = (struct tcpip_state *)h->cprivate; TRC(fprintf(stderr, "tcpip_put: size=%d\n", size)); + h->io_pending = 0; if (state->towrite < 0) { state->towrite = size; @@ -684,29 +980,87 @@ int tcpip_put(COMSTACK h, char *buf, int size) } while (state->towrite > state->written) { - if ((res = send(h->iofile, buf + state->written, size - - state->written, 0)) < 0) - { + if ((res = send(h->iofile, buf + state->written, size - + state->written, 0)) < 0) + { + if ( #ifdef WIN32 - if (WSAGetLastError() == WSAEWOULDBLOCK) + WSAGetLastError() == WSAEWOULDBLOCK #else - if (errno == EAGAIN) -#endif - { - TRC(fprintf(stderr, " Flow control stop\n")); - return 1; - } - h->cerrno = CSYSERR; - return -1; - } - state->written += res; - TRC(fprintf(stderr, " Wrote %d, written=%d, nbytes=%d\n", - res, state->written, size)); + errno == EAGAIN +#endif + ) + { + TRC(fprintf(stderr, " Flow control stop\n")); + h->io_pending = CS_WANT_WRITE; + return 1; + } + h->cerrno = CSYSERR; + return -1; + } + state->written += res; + TRC(fprintf(stderr, " Wrote %d, written=%d, nbytes=%d\n", + res, state->written, size)); + } + state->towrite = state->written = -1; + TRC(fprintf(stderr, " Ok\n")); + return 0; +} + + +#if HAVE_OPENSSL_SSL_H +/* + * Returns 1, 0 or -1 + * In nonblocking mode, you must call again with same buffer while + * return value is 1. + */ +int ssl_put(COMSTACK h, char *buf, int size) +{ + int res; + struct tcpip_state *state = (struct tcpip_state *)h->cprivate; + + TRC(fprintf(stderr, "ssl_put: size=%d\n", size)); + h->io_pending = 0; + if (state->towrite < 0) + { + state->towrite = size; + state->written = 0; + } + else if (state->towrite != size) + { + h->cerrno = CSWRONGBUF; + return -1; + } + while (state->towrite > state->written) + { + res = SSL_write (state->ssl, buf + state->written, + size - state->written); + if (res <= 0) + { + int ssl_err = SSL_get_error(state->ssl, res); + if (ssl_err == SSL_ERROR_WANT_READ) + { + h->io_pending = CS_WANT_READ; + yaz_log (LOG_LOG, "SSL_write. want_read"); + return 1; + } + if (ssl_err == SSL_ERROR_WANT_WRITE) + { + h->io_pending = CS_WANT_WRITE; + yaz_log (LOG_LOG, "SSL_write. want_write"); + return 1; + } + return -1; + } + state->written += res; + TRC(fprintf(stderr, " Wrote %d, written=%d, nbytes=%d\n", + res, state->written, size)); } state->towrite = state->written = -1; TRC(fprintf(stderr, " Ok\n")); return 0; } +#endif int tcpip_close(COMSTACK h) { @@ -714,13 +1068,31 @@ int tcpip_close(COMSTACK h) TRC(fprintf(stderr, "tcpip_close\n")); if (h->iofile != -1) + { +#if HAVE_OPENSSL_SSL_H + if (sp->ssl) + { + SSL_shutdown (sp->ssl); + } +#endif #ifdef WIN32 closesocket(h->iofile); #else close(h->iofile); #endif + } if (sp->altbuf) xfree(sp->altbuf); +#if HAVE_OPENSSL_SSL_H + if (sp->ssl) + { + TRC (fprintf(stderr, "SSL_free\n")); + SSL_free (sp->ssl); + } + sp->ssl = 0; + if (sp->ctx_alloc) + SSL_CTX_free (sp->ctx_alloc); +#endif xfree(sp); xfree(h); return 0; @@ -746,5 +1118,9 @@ char *tcpip_addrstr(COMSTACK h) else r = inet_ntoa(addr.sin_addr); sprintf(buf, "tcp:%s", r); +#if HAVE_OPENSSL_SSL_H + if (sp->ctx) + sprintf(buf, "ssl:%s", r); +#endif return buf; } diff --git a/configure b/configure index 25ba5c6..943c337 100755 --- a/configure +++ b/configure @@ -24,9 +24,11 @@ ac_help="$ac_help ac_help="$ac_help --disable-comp use old encoders, i.e. disable the YAZ ASN.1 Compiler" ac_help="$ac_help + --with-openssl[=DIR] OpenSSL library in DIR" +ac_help="$ac_help --enable-tcpd[=PREFIX] enable TCP wrapper for server if available" ac_help="$ac_help - --enable-threads enable POSIX threads" + --disable-threads disable POSIX threads" # Initialize some variables set by options. # The variables have the same names as the options, with @@ -568,7 +570,7 @@ ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:572: checking for a BSD compatible install" >&5 +echo "configure:574: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -621,7 +623,7 @@ test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' echo $ac_n "checking whether build environment is sane""... $ac_c" 1>&6 -echo "configure:625: checking whether build environment is sane" >&5 +echo "configure:627: checking whether build environment is sane" >&5 # Just in case sleep 1 echo timestamp > conftestfile @@ -678,7 +680,7 @@ test "$program_suffix" != NONE && test "$program_transform_name" = "" && program_transform_name="s,x,x," echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 -echo "configure:682: checking whether ${MAKE-make} sets \${MAKE}" >&5 +echo "configure:684: checking whether ${MAKE-make} sets \${MAKE}" >&5 set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -724,7 +726,7 @@ EOF missing_dir=`cd $ac_aux_dir && pwd` echo $ac_n "checking for working aclocal""... $ac_c" 1>&6 -echo "configure:728: checking for working aclocal" >&5 +echo "configure:730: checking for working aclocal" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -737,7 +739,7 @@ else fi echo $ac_n "checking for working autoconf""... $ac_c" 1>&6 -echo "configure:741: checking for working autoconf" >&5 +echo "configure:743: checking for working autoconf" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -750,7 +752,7 @@ else fi echo $ac_n "checking for working automake""... $ac_c" 1>&6 -echo "configure:754: checking for working automake" >&5 +echo "configure:756: checking for working automake" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -763,7 +765,7 @@ else fi echo $ac_n "checking for working autoheader""... $ac_c" 1>&6 -echo "configure:767: checking for working autoheader" >&5 +echo "configure:769: checking for working autoheader" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -776,7 +778,7 @@ else fi echo $ac_n "checking for working makeinfo""... $ac_c" 1>&6 -echo "configure:780: checking for working makeinfo" >&5 +echo "configure:782: checking for working makeinfo" >&5 # Run test in a subshell; some versions of sh will print an error if # an executable is not found, even if stderr is redirected. # Redirect stdin to placate older versions of autoconf. Sigh. @@ -793,7 +795,7 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:797: checking for $ac_word" >&5 +echo "configure:799: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -823,7 +825,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:827: checking for $ac_word" >&5 +echo "configure:829: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -874,7 +876,7 @@ fi # Extract the first word of "cl", so it can be a program name with args. set dummy cl; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:878: checking for $ac_word" >&5 +echo "configure:880: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -906,7 +908,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:910: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:912: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -917,12 +919,12 @@ cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF -#line 921 "configure" +#line 923 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:926: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:928: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -948,12 +950,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:952: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:954: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:957: checking whether we are using GNU C" >&5 +echo "configure:959: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -962,7 +964,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:966: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:968: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -981,7 +983,7 @@ ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:985: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:987: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1013,7 +1015,7 @@ else fi echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1017: checking how to run the C preprocessor" >&5 +echo "configure:1019: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1028,13 +1030,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1038: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1040: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1045,13 +1047,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1055: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1057: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1062,13 +1064,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1072: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1074: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1104,7 +1106,7 @@ echo "$ac_t""$CPP" 1>&6 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:1108: checking for a BSD compatible install" >&5 +echo "configure:1110: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1232,7 +1234,7 @@ else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; } fi echo $ac_n "checking host system type""... $ac_c" 1>&6 -echo "configure:1236: checking host system type" >&5 +echo "configure:1238: checking host system type" >&5 host_alias=$host case "$host_alias" in @@ -1253,7 +1255,7 @@ host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` echo "$ac_t""$host" 1>&6 echo $ac_n "checking build system type""... $ac_c" 1>&6 -echo "configure:1257: checking build system type" >&5 +echo "configure:1259: checking build system type" >&5 build_alias=$build case "$build_alias" in @@ -1273,7 +1275,7 @@ echo "$ac_t""$build" 1>&6 # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1277: checking for $ac_word" >&5 +echo "configure:1279: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1312,7 +1314,7 @@ ac_prog=ld if test "$ac_cv_prog_gcc" = yes; then # Check if gcc -print-prog-name=ld gives a path. echo $ac_n "checking for ld used by GCC""... $ac_c" 1>&6 -echo "configure:1316: checking for ld used by GCC" >&5 +echo "configure:1318: checking for ld used by GCC" >&5 ac_prog=`($CC -print-prog-name=ld) 2>&5` case "$ac_prog" in # Accept absolute paths. @@ -1336,10 +1338,10 @@ echo "configure:1316: checking for ld used by GCC" >&5 esac elif test "$with_gnu_ld" = yes; then echo $ac_n "checking for GNU ld""... $ac_c" 1>&6 -echo "configure:1340: checking for GNU ld" >&5 +echo "configure:1342: checking for GNU ld" >&5 else echo $ac_n "checking for non-GNU ld""... $ac_c" 1>&6 -echo "configure:1343: checking for non-GNU ld" >&5 +echo "configure:1345: checking for non-GNU ld" >&5 fi if eval "test \"`echo '$''{'ac_cv_path_LD'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1375,7 +1377,7 @@ fi test -z "$LD" && { echo "configure: error: no acceptable ld found in \$PATH" 1>&2; exit 1; } echo $ac_n "checking if the linker ($LD) is GNU ld""... $ac_c" 1>&6 -echo "configure:1379: checking if the linker ($LD) is GNU ld" >&5 +echo "configure:1381: checking if the linker ($LD) is GNU ld" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gnu_ld'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1391,7 +1393,7 @@ echo "$ac_t""$ac_cv_prog_gnu_ld" 1>&6 echo $ac_n "checking for BSD-compatible nm""... $ac_c" 1>&6 -echo "configure:1395: checking for BSD-compatible nm" >&5 +echo "configure:1397: checking for BSD-compatible nm" >&5 if eval "test \"`echo '$''{'ac_cv_path_NM'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1428,7 +1430,7 @@ echo "$ac_t""$NM" 1>&6 echo $ac_n "checking whether ln -s works""... $ac_c" 1>&6 -echo "configure:1432: checking whether ln -s works" >&5 +echo "configure:1434: checking whether ln -s works" >&5 if eval "test \"`echo '$''{'ac_cv_prog_LN_S'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1477,8 +1479,8 @@ test x"$silent" = xyes && libtool_flags="$libtool_flags --silent" case "$host" in *-*-irix6*) # Find out which ABI we are using. - echo '#line 1481 "configure"' > conftest.$ac_ext - if { (eval echo configure:1482: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + echo '#line 1483 "configure"' > conftest.$ac_ext + if { (eval echo configure:1484: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then case "`/usr/bin/file conftest.o`" in *32-bit*) LD="${LD-ld} -32" @@ -1499,19 +1501,19 @@ case "$host" in SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -belf" echo $ac_n "checking whether the C compiler needs -belf""... $ac_c" 1>&6 -echo "configure:1503: checking whether the C compiler needs -belf" >&5 +echo "configure:1505: checking whether the C compiler needs -belf" >&5 if eval "test \"`echo '$''{'lt_cv_cc_needs_belf'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1517: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* lt_cv_cc_needs_belf=yes else @@ -1637,7 +1639,7 @@ else HFILE=${srcdir}/asn/prt-proto.h fi echo $ac_n "checking whether proto.h needs to be generated""... $ac_c" 1>&6 -echo "configure:1641: checking whether proto.h needs to be generated" >&5 +echo "configure:1643: checking whether proto.h needs to be generated" >&5 yaz_include=${srcdir}/include/yaz if test -r ${yaz_include}/proto.h && cmp -s $HFILE ${yaz_include}/proto.h; then echo "$ac_t""no" 1>&6 @@ -1650,12 +1652,12 @@ else fi checkBoth=0 echo $ac_n "checking for connect""... $ac_c" 1>&6 -echo "configure:1654: checking for connect" >&5 +echo "configure:1656: checking for connect" >&5 if eval "test \"`echo '$''{'ac_cv_func_connect'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1684: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_connect=yes" else @@ -1699,7 +1701,7 @@ fi if test "$ac_cv_func_connect" = "no"; then echo $ac_n "checking for main in -lsocket""... $ac_c" 1>&6 -echo "configure:1703: checking for main in -lsocket" >&5 +echo "configure:1705: checking for main in -lsocket" >&5 ac_lib_var=`echo socket'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1707,14 +1709,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lsocket $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1720: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1740,12 +1742,12 @@ if test "$checkBoth" = "1"; then oldLibs=$LIBS LIBS="$LIBS -lsocket -lnsl" echo $ac_n "checking for accept""... $ac_c" 1>&6 -echo "configure:1744: checking for accept" >&5 +echo "configure:1746: checking for accept" >&5 if eval "test \"`echo '$''{'ac_cv_func_accept'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1774: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_accept=yes" else @@ -1790,12 +1792,12 @@ fi fi echo $ac_n "checking for gethostbyname""... $ac_c" 1>&6 -echo "configure:1794: checking for gethostbyname" >&5 +echo "configure:1796: checking for gethostbyname" >&5 if eval "test \"`echo '$''{'ac_cv_func_gethostbyname'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1824: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_gethostbyname=yes" else @@ -1836,7 +1838,7 @@ if eval "test \"`echo '$ac_cv_func_'gethostbyname`\" = yes"; then else echo "$ac_t""no" 1>&6 echo $ac_n "checking for main in -lnsl""... $ac_c" 1>&6 -echo "configure:1840: checking for main in -lnsl" >&5 +echo "configure:1842: checking for main in -lnsl" >&5 ac_lib_var=`echo nsl'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1844,14 +1846,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lnsl $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1857: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1873,9 +1875,150 @@ fi fi +openssl=no +# Check whether --with-openssl or --without-openssl was given. +if test "${with_openssl+set}" = set; then + withval="$with_openssl" + openssl=$withval +fi + +if test "$openssl" = "yes"; then + echo $ac_n "checking for main in -lcrypto""... $ac_c" 1>&6 +echo "configure:1888: checking for main in -lcrypto" >&5 +ac_lib_var=`echo crypto'_'main | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lcrypto $LIBS" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_lib=HAVE_LIB`echo crypto | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <&6 +fi + + echo $ac_n "checking for SSL_new in -lssl""... $ac_c" 1>&6 +echo "configure:1931: checking for SSL_new in -lssl" >&5 +ac_lib_var=`echo ssl'_'SSL_new | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lssl $LIBS" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_lib=HAVE_LIB`echo ssl | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <&6 +fi + + if test "$ac_cv_lib_ssl_SSL_new" = "yes"; then + for ac_hdr in openssl/ssl.h +do +ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` +echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 +echo "configure:1982: checking for $ac_hdr" >&5 +if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1992: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +if test -z "$ac_err"; then + rm -rf conftest* + eval "ac_cv_header_$ac_safe=yes" +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_header_$ac_safe=no" +fi +rm -f conftest* +fi +if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` + cat >> confdefs.h <&6 +fi +done + + fi +fi READLINE_LIBS="" echo $ac_n "checking for readline in -lreadline""... $ac_c" 1>&6 -echo "configure:1879: checking for readline in -lreadline" >&5 +echo "configure:2022: checking for readline in -lreadline" >&5 ac_lib_var=`echo readline'_'readline | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1883,7 +2026,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lreadline $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2041: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1916,7 +2059,7 @@ fi if test "$ac_cv_lib_readline_readline" = "no"; then echo $ac_n "checking for readline in -lreadline""... $ac_c" 1>&6 -echo "configure:1920: checking for readline in -lreadline" >&5 +echo "configure:2063: checking for readline in -lreadline" >&5 ac_lib_var=`echo readline'_'readline | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1924,7 +2067,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lreadline $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2082: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1957,7 +2100,7 @@ fi fi echo $ac_n "checking for add_history in -lhistory""... $ac_c" 1>&6 -echo "configure:1961: checking for add_history in -lhistory" >&5 +echo "configure:2104: checking for add_history in -lhistory" >&5 ac_lib_var=`echo history'_'add_history | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1965,7 +2108,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lhistory $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2123: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2001,17 +2144,17 @@ if test "$ac_cv_lib_readline_readline" = "yes"; then do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:2005: checking for $ac_hdr" >&5 +echo "configure:2148: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2015: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2158: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -2041,12 +2184,12 @@ fi for ac_func in vsnprintf gettimeofday do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2045: checking for $ac_func" >&5 +echo "configure:2188: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2216: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2107,10 +2250,10 @@ if test "$enable_tcpd" != ""; then CPPFLAGS="$CPPFLAGS -I$enable_tcpd/include" fi echo $ac_n "checking for working tcpd.h""... $ac_c" 1>&6 -echo "configure:2111: checking for working tcpd.h" >&5 +echo "configure:2254: checking for working tcpd.h" >&5 LIBS="$LIBS -lwrap -lnsl" cat > conftest.$ac_ext < #include @@ -2121,7 +2264,7 @@ struct request_info request_info; int i; i = hosts_access(&request_info); ; return 0; } EOF -if { (eval echo configure:2125: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2268: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* tcpd_ok=1 else @@ -2144,12 +2287,12 @@ EOF fi fi echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:2148: checking for ANSI C header files" >&5 +echo "configure:2291: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -2157,7 +2300,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2161: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2304: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -2174,7 +2317,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -2192,7 +2335,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -2213,7 +2356,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -2224,7 +2367,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:2228: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2371: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else @@ -2255,12 +2398,14 @@ if test "${enable_threads+set}" = set; then enableval="$enable_threads" enable_threads=$enableval else - enable_threads=no + enable_threads=yes fi + if test "$enable_threads" = "yes"; then + OLIBS=$LIBS echo $ac_n "checking for main in -lpthread""... $ac_c" 1>&6 -echo "configure:2264: checking for main in -lpthread" >&5 +echo "configure:2409: checking for main in -lpthread" >&5 ac_lib_var=`echo pthread'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2268,14 +2413,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lpthread $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2424: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -2303,9 +2448,9 @@ else fi echo $ac_n "checking for working POSIX Threads""... $ac_c" 1>&6 -echo "configure:2307: checking for working POSIX Threads" >&5 +echo "configure:2452: checking for working POSIX Threads" >&5 cat > conftest.$ac_ext < int func(void *p) { return 0; } @@ -2316,7 +2461,7 @@ int main() { int r = pthread_create (&pthread_id, 0, func, 0); ; return 0; } EOF -if { (eval echo configure:2320: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2465: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* thread_ok=yes else @@ -2327,18 +2472,24 @@ else fi rm -f conftest* if test "$thread_ok" = "yes"; then + LIBTHREAD=-lpthread echo "$ac_t""yes" 1>&6 - cat >> confdefs.h <<\EOF -#define HAVE_PTHREAD_H 1 -EOF - - cat >> confdefs.h <<\EOF -#define _REENTRANT 1 -EOF - + HAVETHREADS=1 else + LIBTHREAD="" echo "$ac_t""no" 1>&6 + HAVETHREADS=0 fi + LIBS=$OLIBS +fi + + +if test $HAVETHREADS = "1"; then + ISTHR_TRUE= + ISTHR_FALSE='#' +else + ISTHR_TRUE='#' + ISTHR_FALSE= fi YAZ_SRC_ROOT=`pwd` @@ -2546,6 +2697,9 @@ s%@LIBTOOL@%$LIBTOOL%g s%@ASNMODULE@%$ASNMODULE%g s%@ILLMODULE@%$ILLMODULE%g s%@ILLLIB@%$ILLLIB%g +s%@LIBTHREAD@%$LIBTHREAD%g +s%@ISTHR_TRUE@%$ISTHR_TRUE%g +s%@ISTHR_FALSE@%$ISTHR_FALSE%g s%@YAZ_SRC_ROOT@%$YAZ_SRC_ROOT%g s%@SUBDIRS_VAR@%$SUBDIRS_VAR%g diff --git a/configure.in b/configure.in index 16c7a51..706e187 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl YAZ Toolkit, Index Data 1994-2000 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.37 2000-10-11 10:40:56 adam Exp $ +dnl $Id: configure.in,v 1.38 2000-11-23 10:58:32 adam Exp $ AC_INIT(include/yaz/yaz-version.h) AM_INIT_AUTOMAKE(yaz, 1.7) dnl @@ -55,6 +55,16 @@ if test "$checkBoth" = "1"; then fi AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"])) dnl +dnl ------ Open SSL +openssl=no +AC_ARG_WITH(openssl, [ --with-openssl[=DIR] OpenSSL library in DIR], [openssl=$withval]) +if test "$openssl" = "yes"; then + AC_CHECK_LIB(crypto, main) + AC_CHECK_LIB(ssl, SSL_new) + if test "$ac_cv_lib_ssl_SSL_new" = "yes"; then + AC_CHECK_HEADERS(openssl/ssl.h) + fi +fi dnl ------ GNU Readline READLINE_LIBS="" AC_CHECK_LIB(readline, readline, [READLINE_LIBS="$READLINE_LIBS -lreadline"]) @@ -103,8 +113,10 @@ if test "$ac_cv_header_stdc" = "no"; then fi dnl dnl ------ Threads -AC_ARG_ENABLE(threads, [ --enable-threads enable POSIX threads],[enable_threads=$enableval],[enable_threads=no]) +AC_ARG_ENABLE(threads, [ --disable-threads disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes]) +AC_SUBST(LIBTHREAD) if test "$enable_threads" = "yes"; then + OLIBS=$LIBS AC_CHECK_LIB(pthread,main) AC_MSG_CHECKING(for working POSIX Threads) AC_TRY_LINK([#include @@ -114,13 +126,17 @@ if test "$enable_threads" = "yes"; then int r = pthread_create (&pthread_id, 0, func, 0);], thread_ok=yes,thread_ok=no) if test "$thread_ok" = "yes"; then + LIBTHREAD=-lpthread AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_PTHREAD_H) - AC_DEFINE(_REENTRANT) + HAVETHREADS=1 else + LIBTHREAD="" AC_MSG_RESULT(no) + HAVETHREADS=0 fi + LIBS=$OLIBS fi +AM_CONDITIONAL(ISTHR, test $HAVETHREADS = "1") dnl ------ Using this for "in-source" yaz-config AC_SUBST(YAZ_SRC_ROOT) YAZ_SRC_ROOT=`pwd` diff --git a/doc/Makefile.in b/doc/Makefile.in index 41aafda..a649db0 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/ill/Makefile.in b/ill/Makefile.in index 5d6e0c9..bfa1aa8 100644 --- a/ill/Makefile.in +++ b/ill/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/include/Makefile.in b/include/Makefile.in index 67e11b7..277d702 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ @@ -108,6 +109,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) # (which will cause the Makefiles to be regenerated when you run `make'); # (2) otherwise, pass the desired values on the `make' command line. +@SET_MAKE@ + all-recursive install-data-recursive install-exec-recursive \ installdirs-recursive install-recursive uninstall-recursive \ check-recursive installcheck-recursive info-recursive dvi-recursive: @@ -134,11 +137,10 @@ maintainer-clean-recursive: @set fnord $(MAKEFLAGS); amf=$$2; \ dot_seen=no; \ rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = "."; then :; else \ - rev="$$subdir $$rev"; \ - fi; \ + rev="$$subdir $$rev"; \ + test "$$subdir" = "." && dot_seen=yes; \ done; \ - rev="$$rev ."; \ + test "$$dot_seen" = "no" && rev=". $$rev"; \ target=`echo $@ | sed s/-recursive//`; \ for subdir in $$rev; do \ echo "Making $$target in $$subdir"; \ diff --git a/include/yaz/Makefile.in b/include/yaz/Makefile.in index 3c2bbb2..1c2072a 100644 --- a/include/yaz/Makefile.in +++ b/include/yaz/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/include/yaz/comstack.h b/include/yaz/comstack.h index 6e22a72..8abe302 100644 --- a/include/yaz/comstack.h +++ b/include/yaz/comstack.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: comstack.h,v 1.2 2000-02-28 11:20:06 adam Exp $ + * $Id: comstack.h,v 1.3 2000-11-23 10:58:32 adam Exp $ */ #ifndef COMSTACK_H @@ -67,7 +67,7 @@ YAZ_BEGIN_CDECL struct comstack; typedef struct comstack *COMSTACK; -typedef COMSTACK (*CS_TYPE)(int s, int blocking, int protocol); +typedef COMSTACK (*CS_TYPE)(int s, int blocking, int protocol, void *vp); struct comstack { @@ -84,11 +84,14 @@ struct comstack #define CS_INCON 2 #define CS_OUTCON 3 #define CS_DATAXFER 4 +#define CS_ACCEPT 5 +#define CS_CONNECT 6 int newfd; /* storing new descriptor between listen and accept */ int blocking; /* is this link (supposed to be) blocking? */ + unsigned io_pending; /* flag to signal read / write op is incomplete */ int event; /* current event */ #define CS_NONE 0 -#define CS_CONNECT 1 +#define CS_CONNECTING 1 #define CS_DISCON 2 #define CS_LISTEN 3 #define CS_DATA 4 @@ -120,9 +123,9 @@ struct comstack #define cs_listen_check(handle, ap, al, cf, cd) ((*(handle)->f_listen)(handle, ap, al, cf, cd)) #define cs_accept(handle) ((*(handle)->f_accept)(handle)) #define cs_close(handle) ((*(handle)->f_close)(handle)) -#define cs_create(type, blocking, proto) ((*type)(-1, blocking, proto)) +#define cs_create(type, blocking, proto) ((*type)(-1, blocking, proto, 0)) #define cs_createbysocket(sock, type, blocking, proto) \ - ((*type)(sock, blocking, proto)) + ((*type)(sock, blocking, proto, 0)) #define cs_type(handle) ((handle)->type) #define cs_fileno(handle) ((handle)->iofile) #define cs_stackerr(handle) ((handle)->stackerr) @@ -131,7 +134,11 @@ struct comstack #define cs_getproto(handle) ((handle)->protocol) #define cs_addrstr(handle) ((*(handle)->f_addrstr)(handle)) #define cs_straddr(handle, str) ((*(handle)->f_straddr)(handle, str)) +#define cs_want_read(handle) ((handle)->io_pending & CS_WANT_READ) +#define cs_want_write(handle) ((handle)->io_pending & CS_WANT_WRITE) +#define CS_WANT_READ 1 +#define CS_WANT_WRITE 2 YAZ_EXPORT const char *cs_strerror(COMSTACK h); YAZ_EXPORT const char *cs_errmsg(int n); diff --git a/include/yaz/tcpip.h b/include/yaz/tcpip.h index a4d66a6..ab74553 100644 --- a/include/yaz/tcpip.h +++ b/include/yaz/tcpip.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: tcpip.h,v $ - * Revision 1.2 2000-02-28 11:20:06 adam + * Revision 1.3 2000-11-23 10:58:32 adam + * SSL comstack support. Separate POSIX thread support library. + * + * Revision 1.2 2000/02/28 11:20:06 adam * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL. * * Revision 1.1 1999/11/30 13:47:11 adam @@ -94,7 +97,8 @@ YAZ_BEGIN_CDECL YAZ_EXPORT int completeWAIS(const unsigned char *buf, int len); YAZ_EXPORT struct sockaddr_in *tcpip_strtoaddr(const char *str); -YAZ_EXPORT COMSTACK tcpip_type(int s, int blocking, int protocol); +YAZ_EXPORT COMSTACK tcpip_type(int s, int blocking, int protocol, void *vp); +YAZ_EXPORT COMSTACK ssl_type(int s, int blocking, int protocol, void *vp); YAZ_END_CDECL diff --git a/install-sh b/install-sh index ebc6691..e9de238 100755 --- a/install-sh +++ b/install-sh @@ -1,4 +1,4 @@ -#! /bin/sh +#!/bin/sh # # install - install a program, script, or datafile # This comes from X11R5 (mit/util/scripts/install.sh). @@ -118,6 +118,7 @@ if [ x"$dir_arg" != x ]; then if [ -d $dst ]; then instcmd=: + chmodcmd="" else instcmd=mkdir fi diff --git a/lib/Makefile.am b/lib/Makefile.am index 3f934cf..ff85dc5 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,10 @@ -## $Id: Makefile.am,v 1.8 2000-10-11 11:36:15 adam Exp $ +## $Id: Makefile.am,v 1.9 2000-11-23 10:58:32 adam Exp $ -lib_LTLIBRARIES = libyaz.la +if ISTHR +extra=libyazthread.la +endif + +lib_LTLIBRARIES = libyaz.la $(extra) # If the line below is omitted the LINK variable is # not set in Makefile.in and it will NOT work .. @@ -9,11 +13,22 @@ EXTRA_libyaz_la_SOURCES=x.c # No real sources libyaz_la_SOURCES= +libyazthread_la_SOURCES=nmem.c statserv.c + LDFLAGS=-version-info 1:0:0 +nmem.c: + ln -s $(srcdir)/../util/nmem.c + +statserv.c: + ln -s $(srcdir)/../server/statserv.c + +INCLUDES =-I$(srcdir)/../include -I$(srcdir)/../server -D_REENTRANT=1 -DHAVE_PTHREAD_H=1 + bin_SCRIPTS = yaz-config libyaz_la_LIBADD=../odr/libodr.la ../$(ASNMODULE)/libasn.la \ ../comstack/libcomstack.la ../server/libserver.la \ ../zutil/libzutil.la ../util/libutil.la ../ccl/libccl.la \ ../retrieval/libret.la $(ILLLIB) + diff --git a/lib/Makefile.in b/lib/Makefile.in index 6041973..40d7e64 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ @@ -79,7 +80,9 @@ SUBDIRS_VAR = @SUBDIRS_VAR@ VERSION = @VERSION@ YAZ_SRC_ROOT = @YAZ_SRC_ROOT@ -lib_LTLIBRARIES = libyaz.la +@ISTHR_TRUE@extra = libyazthread.la + +lib_LTLIBRARIES = libyaz.la $(extra) # If the line below is omitted the LINK variable is # not set in Makefile.in and it will NOT work .. @@ -88,8 +91,12 @@ EXTRA_libyaz_la_SOURCES = x.c # No real sources libyaz_la_SOURCES = +libyazthread_la_SOURCES = nmem.c statserv.c + LDFLAGS = -version-info 1:0:0 +INCLUDES = -I$(srcdir)/../include -I$(srcdir)/../server -D_REENTRANT=1 -DHAVE_PTHREAD_H=1 + bin_SCRIPTS = yaz-config libyaz_la_LIBADD = ../odr/libodr.la ../$(ASNMODULE)/libasn.la ../comstack/libcomstack.la ../server/libserver.la ../zutil/libzutil.la ../util/libutil.la ../ccl/libccl.la ../retrieval/libret.la $(ILLLIB) @@ -107,6 +114,9 @@ libyaz_la_DEPENDENCIES = ../odr/libodr.la ../$(ASNMODULE)/libasn.la \ ../comstack/libcomstack.la ../server/libserver.la ../zutil/libzutil.la \ ../util/libutil.la ../ccl/libccl.la ../retrieval/libret.la libyaz_la_OBJECTS = +libyazthread_la_LDFLAGS = +libyazthread_la_LIBADD = +libyazthread_la_OBJECTS = nmem.lo statserv.lo SCRIPTS = $(bin_SCRIPTS) CFLAGS = @CFLAGS@ @@ -121,9 +131,9 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = gtar GZIP_ENV = --best -DEP_FILES = .deps/x.P -SOURCES = $(libyaz_la_SOURCES) $(EXTRA_libyaz_la_SOURCES) -OBJECTS = $(libyaz_la_OBJECTS) +DEP_FILES = .deps/nmem.P .deps/statserv.P .deps/x.P +SOURCES = $(libyaz_la_SOURCES) $(EXTRA_libyaz_la_SOURCES) $(libyazthread_la_SOURCES) +OBJECTS = $(libyaz_la_OBJECTS) $(libyazthread_la_OBJECTS) all: all-redirect .SUFFIXES: @@ -198,6 +208,9 @@ maintainer-clean-libtool: libyaz.la: $(libyaz_la_OBJECTS) $(libyaz_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libyaz_la_LDFLAGS) $(libyaz_la_OBJECTS) $(libyaz_la_LIBADD) $(LIBS) +libyazthread.la: $(libyazthread_la_OBJECTS) $(libyazthread_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libyazthread_la_LDFLAGS) $(libyazthread_la_OBJECTS) $(libyazthread_la_LIBADD) $(LIBS) + install-binSCRIPTS: $(bin_SCRIPTS) @$(NORMAL_INSTALL) $(mkinstalldirs) $(DESTDIR)$(bindir) @@ -377,6 +390,12 @@ distclean-generic clean-generic maintainer-clean-generic clean \ mostlyclean distclean maintainer-clean +nmem.c: + ln -s $(srcdir)/../util/nmem.c + +statserv.c: + ln -s $(srcdir)/../server/statserv.c + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/mkinstalldirs b/mkinstalldirs index 3614101..7cf5086 100755 --- a/mkinstalldirs +++ b/mkinstalldirs @@ -4,7 +4,7 @@ # Created: 1993-05-16 # Public domain -# $Id: mkinstalldirs,v 1.1 2000-02-28 11:20:05 adam Exp $ +# $Id: mkinstalldirs,v 1.2 2000-11-23 10:58:32 adam Exp $ errstatus=0 diff --git a/odr/Makefile.in b/odr/Makefile.in index 7a573d7..db2aea4 100644 --- a/odr/Makefile.in +++ b/odr/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/retrieval/Makefile.in b/retrieval/Makefile.in index d91215b..c379e86 100644 --- a/retrieval/Makefile.in +++ b/retrieval/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/server/Makefile.am b/server/Makefile.am index de8218e..01e0359 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.3 2000-04-05 07:39:55 adam Exp $ +## $Id: Makefile.am,v 1.4 2000-11-23 10:58:32 adam Exp $ noinst_LTLIBRARIES=libserver.la @@ -9,4 +9,4 @@ EXTRA_DIST=service.c LIBS = -INCLUDES=-I$(srcdir)/../include +INCLUDES=-I$(srcdir)/../include diff --git a/server/Makefile.in b/server/Makefile.in index a1e4815..e5be36f 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ @@ -88,7 +89,7 @@ EXTRA_DIST = service.c LIBS = -INCLUDES = -I$(srcdir)/../include +INCLUDES = -I$(srcdir)/../include mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) diff --git a/server/seshigh.c b/server/seshigh.c index 277050a..18f604b 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: seshigh.c,v $ - * Revision 1.110 2000-10-02 13:05:32 adam + * Revision 1.111 2000-11-23 10:58:32 adam + * SSL comstack support. Separate POSIX thread support library. + * + * Revision 1.110 2000/10/02 13:05:32 adam * Fixed bug introduced by previous commit. * * Revision 1.109 2000/10/02 11:07:44 adam @@ -435,6 +438,9 @@ association *create_association(IOCHAN channel, COMSTACK link) anew->init = 0; anew->client_chan = channel; anew->client_link = link; + anew->cs_get_mask = 0; + anew->cs_put_mask = 0; + anew->cs_accept_mask = 0; if (!(anew->decode = odr_createmem(ODR_DECODE)) || !(anew->encode = odr_createmem(ODR_ENCODE))) return 0; @@ -578,12 +584,37 @@ void ir_session(IOCHAN h, int event) } return; } - if (event & EVENT_INPUT || event & EVENT_WORK) /* input */ + if (event & assoc->cs_accept_mask) + { + yaz_log (LOG_DEBUG, "ir_session (accept)"); + if (!cs_accept (conn)) + { + yaz_log (LOG_LOG, "accept failed"); + destroy_association(assoc); + iochan_destroy(h); + } + iochan_clearflag (h, EVENT_OUTPUT|EVENT_OUTPUT); + if (conn->io_pending) + { /* cs_accept didn't complete */ + assoc->cs_accept_mask = + ((conn->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) | + ((conn->io_pending & CS_WANT_READ) ? EVENT_INPUT : 0); + + iochan_setflag (h, assoc->cs_accept_mask); + } + else + { /* cs_accept completed. Prepare for reading (cs_get) */ + assoc->cs_accept_mask = 0; + assoc->cs_get_mask = EVENT_INPUT; + iochan_setflag (h, assoc->cs_get_mask); + } + return; + } + if ((event & assoc->cs_get_mask) || (event & EVENT_WORK)) /* input */ { - if (event & EVENT_INPUT) + if ((assoc->cs_put_mask & EVENT_INPUT) == 0 && (event & assoc->cs_get_mask)) { yaz_log(LOG_DEBUG, "ir_session (input)"); - assert(assoc && conn); /* We aren't speaking to this fellow */ if (assoc->state == ASSOC_DEAD) { @@ -593,6 +624,7 @@ void ir_session(IOCHAN h, int event) iochan_destroy(h); return; } + assoc->cs_get_mask = EVENT_INPUT; if ((res = cs_get(conn, &assoc->input_buffer, &assoc->input_buffer_len)) <= 0) { @@ -603,7 +635,12 @@ void ir_session(IOCHAN h, int event) return; } else if (res == 1) /* incomplete read - wait for more */ + { + if (conn->io_pending & CS_WANT_WRITE) + assoc->cs_get_mask |= EVENT_OUTPUT; + iochan_setflag(h, assoc->cs_get_mask); return; + } if (cs_more(conn)) /* more stuff - call us again later, please */ iochan_setevent(h, EVENT_INPUT); @@ -642,34 +679,43 @@ void ir_session(IOCHAN h, int event) do_close_req(assoc, Z_Close_systemProblem, msg, req); } } - if (event & EVENT_OUTPUT) + if (event & assoc->cs_put_mask) { request *req = request_head(&assoc->outgoing); + assoc->cs_put_mask = 0; yaz_log(LOG_DEBUG, "ir_session (output)"); req->state = REQUEST_PENDING; switch (res = cs_put(conn, req->response, req->len_response)) { - case -1: - yaz_log(LOG_LOG, "Connection closed by client"); - cs_close(conn); - destroy_association(assoc); - iochan_destroy(h); - break; - case 0: /* all sent - release the request structure */ - yaz_log(LOG_DEBUG, "Wrote PDU, %d bytes", req->len_response); - nmem_destroy(req->request_mem); - request_deq(&assoc->outgoing); - request_release(req); - if (!request_head(&assoc->outgoing)) - iochan_clearflag(h, EVENT_OUTPUT); - break; - /* value of 1 -- partial send -- is simply ignored */ + case -1: + yaz_log(LOG_LOG, "Connection closed by client"); + cs_close(conn); + destroy_association(assoc); + iochan_destroy(h); + break; + case 0: /* all sent - release the request structure */ + yaz_log(LOG_DEBUG, "Wrote PDU, %d bytes", req->len_response); + nmem_destroy(req->request_mem); + request_deq(&assoc->outgoing); + request_release(req); + if (!request_head(&assoc->outgoing)) + { /* restore mask for cs_get operation ... */ + iochan_clearflag(h, EVENT_OUTPUT|EVENT_INPUT); + iochan_setflag(h, assoc->cs_get_mask); + } + break; + default: + if (conn->io_pending & CS_WANT_WRITE) + assoc->cs_put_mask |= EVENT_OUTPUT; + if (conn->io_pending & CS_WANT_READ) + assoc->cs_put_mask |= EVENT_INPUT; + iochan_setflag(h, assoc->cs_put_mask); } } if (event & EVENT_EXCEPT) { - yaz_log(LOG_DEBUG, "ir_session (exception)"); + yaz_log(LOG_LOG, "ir_session (exception)"); cs_close(conn); destroy_association(assoc); iochan_destroy(h); @@ -848,6 +894,7 @@ static int process_response(association *assoc, request *req, Z_APDU *res) request_enq(&assoc->outgoing, req); /* turn the work over to the ir_session handler */ iochan_setflag(assoc->client_chan, EVENT_OUTPUT); + assoc->cs_put_mask = EVENT_OUTPUT; /* Is there more work to be done? give that to the input handler too */ #if 1 if (request_head(&assoc->incoming)) @@ -992,6 +1039,12 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->preferredMessageSize = *req->preferredMessageSize; if (assoc->preferredMessageSize > assoc->maximumRecordSize) assoc->preferredMessageSize = assoc->maximumRecordSize; + +#if 0 + assoc->maximumRecordSize = 3000000; + assoc->preferredMessageSize = 3000000; +#endif + resp->preferredMessageSize = &assoc->preferredMessageSize; resp->maximumRecordSize = &assoc->maximumRecordSize; diff --git a/server/session.h b/server/session.h index ec735d6..5217a89 100644 --- a/server/session.h +++ b/server/session.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: session.h,v $ - * Revision 1.23 2000-04-05 07:39:55 adam + * Revision 1.24 2000-11-23 10:58:32 adam + * SSL comstack support. Separate POSIX thread support library. + * + * Revision 1.23 2000/04/05 07:39:55 adam * Added shared library support (libtool). * * Revision 1.22 2000/03/20 19:06:25 adam @@ -156,6 +159,10 @@ typedef struct association int maximumRecordSize; int version; /* highest version-bit set (2 or 3) */ + unsigned cs_get_mask; + unsigned cs_put_mask; + unsigned cs_accept_mask; + struct bend_initrequest *init; #if 0 int (*bend_sort) (); diff --git a/server/statserv.c b/server/statserv.c index 11a7b54..458f664 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -7,7 +7,10 @@ * Chas Woodfield, Fretwell Downing Informatics. * * $Log: statserv.c,v $ - * Revision 1.66 2000-10-06 12:00:28 adam + * Revision 1.67 2000-11-23 10:58:32 adam + * SSL comstack support. Separate POSIX thread support library. + * + * Revision 1.66 2000/10/06 12:00:28 adam * Fixed Handle leak for WIN32. * * Revision 1.65 2000/09/04 08:58:15 adam @@ -387,6 +390,7 @@ void statserv_remove(IOCHAN pIOChannel) } } +/* WIN32 statserv_closedown */ void statserv_closedown() { /* Shouldn't do anything if we are not initialized */ @@ -460,7 +464,8 @@ void event_loop_thread (IOCHAN iochan) event_loop (&iochan); } -static void listener(IOCHAN h, int event) +/* WIN32 listener */ +static void listener(IOCHAN h, int event) { COMSTACK line = (COMSTACK) iochan_getdata(h); association *newas; @@ -482,14 +487,14 @@ static void listener(IOCHAN h, int event) } else if (event == EVENT_OUTPUT) { - COMSTACK new_line; + COMSTACK new_line = cs_accept(line); IOCHAN new_chan; char *a = NULL; - if (!(new_line = cs_accept(line))) + if (!new_line) { yaz_log(LOG_FATAL, "Accept failed."); - iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */ + iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); return; } yaz_log(LOG_DEBUG, "Accept ok"); @@ -509,6 +514,10 @@ static void listener(IOCHAN h, int event) iochan_destroy(h); return; } + newas->cs_get_mask = EVENT_INPUT; + newas->cs_put_mask = 0; + newas->cs_accept_mask = 0; + yaz_log(LOG_DEBUG, "Setting timeout %d", control_block.idle_timeout); iochan_setdata(new_chan, newas); iochan_settimeout(new_chan, control_block.idle_timeout * 60); @@ -563,6 +572,7 @@ void sigterm(int sig) static void *new_session (void *vp); +/* UNIX listener */ static void listener(IOCHAN h, int event) { COMSTACK line = (COMSTACK) iochan_getdata(h); @@ -644,9 +654,9 @@ static void listener(IOCHAN h, int event) /* in dynamic mode, only the child ever comes down here */ else if (event == EVENT_OUTPUT) { - COMSTACK new_line; + COMSTACK new_line = cs_accept(line); - if (!(new_line = cs_accept(line))) + if (!new_line) { yaz_log(LOG_FATAL, "Accept failed."); iochan_setflags(h, EVENT_INPUT | EVENT_EXCEPT); /* reset listener */ @@ -697,8 +707,25 @@ static void *new_session (void *vp) association *newas; IOCHAN new_chan; COMSTACK new_line = (COMSTACK) vp; - if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session, - EVENT_INPUT))) + + unsigned cs_get_mask, cs_accept_mask, mask = + ((new_line->io_pending & CS_WANT_WRITE) ? EVENT_OUTPUT : 0) | + ((new_line->io_pending & CS_WANT_READ) ? EVENT_INPUT : 0); + + if (mask) + { + yaz_log (LOG_LOG, "new_session , accept incomplete"); + cs_accept_mask = mask; /* accept didn't complete */ + cs_get_mask = 0; + } + else + { + yaz_log (LOG_LOG, "new_session , accept complete"); + cs_accept_mask = 0; /* accept completed. */ + cs_get_mask = mask = EVENT_INPUT; + } + + if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session, mask))) { yaz_log(LOG_FATAL, "Failed to create iochan"); return 0; @@ -708,10 +735,14 @@ static void *new_session (void *vp) yaz_log(LOG_FATAL, "Failed to create new assoc."); return 0; } + newas->cs_accept_mask = cs_accept_mask; + newas->cs_get_mask = cs_get_mask; + iochan_setdata(new_chan, newas); iochan_settimeout(new_chan, control_block.idle_timeout * 60); a = cs_addrstr(new_line); yaz_log(LOG_LOG, "Accepted connection from %s", a ? a : "[Unknown]"); + if (control_block.threads) { event_loop(&new_chan); @@ -775,23 +806,24 @@ static void add_listener(char *where, int what) if (!where || sscanf(where, "%[^:]:%s", mode, addr) != 2) { - yaz_log (LOG_WARN, "%s: Address format: ('tcp'|'osi')':'
", me); + yaz_log (LOG_WARN, "%s: Address format: ('tcp'|'ssl')':'
", + me); return; } if (!strcmp(mode, "tcp")) type = tcpip_type; - else if (!strcmp(mode, "osi")) + else if (!strcmp(mode, "ssl")) { -#ifdef USE_XTIMOSI - type = mosi_type; +#if HAVE_OPENSSL_SSL_H + type = ssl_type; #else - yaz_log (LOG_WARN, "OSI Transport not allowed by configuration."); + yaz_log (LOG_WARN, "SSL Transport not allowed by configuration."); return; #endif } else { - yaz_log (LOG_WARN, "You must specify either 'osi:' or 'tcp:'"); + yaz_log (LOG_WARN, "You must specify either 'ssl:' or 'tcp:'"); return; } yaz_log(LOG_LOG, "Adding %s %s listener on %s", @@ -862,7 +894,7 @@ int statserv_start(int argc, char **argv) /* We need to initialize the thread list */ ThreadList_Initialize(); #endif /* WIN32 */ - + #ifdef WIN32 if ((me = strrchr (argv[0], '\\'))) me++; @@ -873,7 +905,7 @@ int statserv_start(int argc, char **argv) #endif if (control_block.options_func(argc, argv)) return(1); - + if (control_block.bend_start) (*control_block.bend_start)(&control_block); #ifdef WIN32 @@ -886,18 +918,16 @@ int statserv_start(int argc, char **argv) logf (LOG_LOG, "Starting server %s pid=%d", me, getpid()); #if 0 sigset_t sigs_to_block; - + sigemptyset(&sigs_to_block); sigaddset (&sigs_to_block, SIGTERM); pthread_sigmask (SIG_BLOCK, &sigs_to_block, 0); - pthread_create (& - - + /* missing... */ #endif if (control_block.dynamic) signal(SIGCHLD, catchchld); } - + signal (SIGPIPE, SIG_IGN); signal (SIGTERM, sigterm); if (*control_block.setuid) { diff --git a/tab/Makefile.in b/tab/Makefile.in index b3b32b4..2e9b73b 100644 --- a/tab/Makefile.in +++ b/tab/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/util/Makefile.am b/util/Makefile.am index 690bece..010e9cc 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,9 +1,11 @@ ## Copyright (C) 1994-2000, Index Data ## All rights reserved. -## $Id: Makefile.am,v 1.7 2000-05-18 11:57:05 adam Exp $ +## $Id: Makefile.am,v 1.8 2000-11-23 10:58:33 adam Exp $ noinst_LTLIBRARIES = libutil.la +#lib_LTLIBRARIES = libyazthread.la + bin_SCRIPTS = yaz-comp EXTRA_DIST = yaz-comp @@ -12,6 +14,8 @@ LIBS = INCLUDES =-I$(srcdir)/../include +libyazthread_la_INCLUDES=-I$(srcdir)/../include + noinst_PROGRAMS = marcdump marcdump_LDADD = libutil.la @@ -20,3 +24,5 @@ marcdump_SOURCES = marcdump.c libutil_la_SOURCES=options.c log.c marcdisp.c oid.c wrbuf.c nmemsdup.c \ xmalloc.c readconf.c tpath.c nmem.c matchstr.c atoin.c + +#libyazthread_la_SOURCES=nmemthread.c xmalloc.c log.c diff --git a/util/Makefile.in b/util/Makefile.in index ad776e5..4152c57 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ @@ -81,6 +82,8 @@ YAZ_SRC_ROOT = @YAZ_SRC_ROOT@ noinst_LTLIBRARIES = libutil.la +#lib_LTLIBRARIES = libyazthread.la + bin_SCRIPTS = yaz-comp EXTRA_DIST = yaz-comp @@ -89,6 +92,8 @@ LIBS = INCLUDES = -I$(srcdir)/../include +libyazthread_la_INCLUDES = -I$(srcdir)/../include + noinst_PROGRAMS = marcdump marcdump_LDADD = libutil.la @@ -387,6 +392,8 @@ distclean-generic clean-generic maintainer-clean-generic clean \ mostlyclean distclean maintainer-clean +#libyazthread_la_SOURCES=nmemthread.c xmalloc.c log.c + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/yaz-config.in b/yaz-config.in index d7b361c..d4282a8 100644 --- a/yaz-config.in +++ b/yaz-config.in @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: yaz-config.in,v 1.3 2000-10-11 12:24:58 adam Exp $ +# $Id: yaz-config.in,v 1.4 2000-11-23 10:58:32 adam Exp $ yazprefix=@prefix@ yaz_echo_cflags=no yaz_echo_libs=no @@ -9,7 +9,7 @@ yaz_echo_source=yes yaz_echo_lalibs=no yaz_src_root=@YAZ_SRC_ROOT@ -yazlibs="@LIBS@" +yazextralibs="@LIBS@" YAZVERSION=@VERSION@ usage() @@ -23,6 +23,8 @@ Options: [--lalibs] [--cflags] [--tabs] +Libraries: + threads EOF exit $1 } @@ -61,6 +63,9 @@ while test $# -gt 0; do --lalibs) yaz_echo_lalibs=yes ;; + threads) + lib_thread=yes + ;; -*) yaz_echo_help=yes ;; @@ -68,20 +73,30 @@ while test $# -gt 0; do shift done +if test "$lib_thread" = "yes"; then + yazextralibs="@LIBTHREAD@ $yazextralibs" + lyaz="-lyazthread -lyaz" +else + lyaz="-lyaz" +fi if test "$yaz_echo_source" = "yes"; then YAZTAB=${yaz_src_root}/tab YAZBIN=${yaz_src_root}/bin - YAZLIB="-L${yaz_src_root}/lib/.libs -lyaz $yazlibs" - YAZLALIB="${yaz_src_root}/lib/libyaz.la $yazlibs" + YAZLIB="-L${yaz_src_root}/lib/.libs $lyaz $yazextralibs" + if test "$lib_thread" = "yes"; then + YAZLALIB="${yaz_src_root}/lib/libyazthread.la ${yaz_src_root}/lib/libyaz.la $yazextralibs" + else + YAZLALIB="${yaz_src_root}/lib/libyazthread.la $yazextralibs" + fi YAZINC="-I${yaz_src_root}/include" else YAZTAB=$yazprefix/share/yaz/tab YAZBIN=$yazprefix/bin if test "$yazprefix" = "/usr"; then - YAZLIB="-lyaz $yazlibs" + YAZLIB="$lyaz $yazextralibs" else - YAZLIB="-L$yazprefix/lib -lyaz $yazlibs" + YAZLIB="-L$yazprefix/lib $lyaz $yazextralibs" fi YAZLALIB=$YAZLIB if test "$yazprefix" = "/usr"; then @@ -91,6 +106,10 @@ else fi fi +if test "$lib_thread" = "yes"; then + YAZINC="$YAZINC -D_REENTRANT" +fi + if test "$yaz_echo_help" = "yes"; then usage 1 1>&2 fi diff --git a/yaz.spec b/yaz.spec index 3483ca8..33afd51 100644 --- a/yaz.spec +++ b/yaz.spec @@ -40,6 +40,10 @@ cd doc; make prefix=$RPM_BUILD_ROOT/usr install /usr/lib/libyaz.so /usr/lib/libyaz.so.1 /usr/lib/libyaz.so.1.0.0 +/usr/lib/libyazthread.a +/usr/lib/libyazthread.so +/usr/lib/libyazthread.so.1 +/usr/lib/libyazthread.so.1.0.0 /usr/include/yaz /usr/share/yaz/doc /usr/share/aclocal/yaz.m4 diff --git a/z39.50/Makefile.in b/z39.50/Makefile.in index 3f3cc0a..188c2ed 100644 --- a/z39.50/Makefile.in +++ b/z39.50/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ diff --git a/ztest/Makefile.am b/ztest/Makefile.am index ae45708..f319c89 100644 --- a/ztest/Makefile.am +++ b/ztest/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.3 2000-04-05 07:39:55 adam Exp $ +## $Id: Makefile.am,v 1.4 2000-11-23 10:58:33 adam Exp $ bin_PROGRAMS=yaz-ztest @@ -6,6 +6,9 @@ yaz_ztest_SOURCES=ztest.c read-grs.c EXTRA_DIST=dummy-records dummy-words dummy-grs -yaz_ztest_LDADD=../lib/libyaz.la +if ISTHR +extra=../lib/libyazthread.la +endif +yaz_ztest_LDADD=$(extra) ../lib/libyaz.la $(LIBTHREAD) INCLUDES=-I$(srcdir)/../include diff --git a/ztest/Makefile.in b/ztest/Makefile.in index 2b95d02..d6b80bb 100644 --- a/ztest/Makefile.in +++ b/ztest/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@ @@ -85,7 +86,8 @@ yaz_ztest_SOURCES = ztest.c read-grs.c EXTRA_DIST = dummy-records dummy-words dummy-grs -yaz_ztest_LDADD = ../lib/libyaz.la +@ISTHR_TRUE@extra = ../lib/libyazthread.la +yaz_ztest_LDADD = $(extra) ../lib/libyaz.la $(LIBTHREAD) INCLUDES = -I$(srcdir)/../include mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs @@ -98,7 +100,9 @@ CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ yaz_ztest_OBJECTS = ztest.o read-grs.o -yaz_ztest_DEPENDENCIES = ../lib/libyaz.la +@ISTHR_TRUE@yaz_ztest_DEPENDENCIES = ../lib/libyazthread.la \ +@ISTHR_TRUE@../lib/libyaz.la +@ISTHR_FALSE@yaz_ztest_DEPENDENCIES = ../lib/libyaz.la yaz_ztest_LDFLAGS = CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/ztest/ztest.c b/ztest/ztest.c index ba7dc20..fa749d6 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -6,7 +6,10 @@ * Chas Woodfield, Fretwell Downing Datasystems. * * $Log: ztest.c,v $ - * Revision 1.34 2000-09-04 08:58:15 adam + * Revision 1.35 2000-11-23 10:58:33 adam + * SSL comstack support. Separate POSIX thread support library. + * + * Revision 1.34 2000/09/04 08:58:15 adam * Added prefix yaz_ for most logging utility functions. * * Revision 1.33 2000/08/10 08:41:26 adam @@ -478,12 +481,21 @@ int ztest_fetch(void *handle, bend_fetch_rr *r) r->output_format = r->request_format; if (r->request_format == VAL_SUTRS) { +#if 0 +/* this section returns a huge record (for testing non-blocking write, etc) */ + r->len = 980000; + r->record = odr_malloc (r->stream, r->len); + memset (r->record, 'x', r->len); +#else +/* this section returns a small record */ char buf[100]; sprintf(buf, "This is dummy SUTRS record number %d\n", r->number); + r->len = strlen(buf); r->record = (char *) odr_malloc (r->stream, r->len+1); strcpy(r->record, buf); +#endif } else if (r->request_format == VAL_GRS1) { diff --git a/zutil/Makefile.in b/zutil/Makefile.in index 317435c..5c77b0f 100644 --- a/zutil/Makefile.in +++ b/zutil/Makefile.in @@ -67,6 +67,7 @@ DLLTOOL = @DLLTOOL@ ILLLIB = @ILLLIB@ ILLMODULE = @ILLMODULE@ LD = @LD@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ MAKEINFO = @MAKEINFO@