X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftcpip.c;h=ffbcf44e0d13d5693841c59a19bdec9e23466eeb;hb=4e3f7be8266559e07dc01ae5d6aba31d30b8bd44;hp=bab44df61fab203c0656340f1aa64400594b4163;hpb=5ad7d533eb01f5f25f7c59f16a2d3c04a99ee041;p=yaz-moved-to-github.git diff --git a/src/tcpip.c b/src/tcpip.c index bab44df..ffbcf44 100644 --- a/src/tcpip.c +++ b/src/tcpip.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2008 Index Data + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. */ /** @@ -25,7 +25,6 @@ #endif #ifdef WIN32 - /* VS 2003 or later has getaddrinfo; older versions do not */ #include #if _MSC_VER >= 1300 @@ -34,14 +33,20 @@ #else #define HAVE_GETADDRINFO 0 #endif +#endif -#else +#if HAVE_NETINET_IN_H #include +#endif +#if HAVE_NETDB_H #include +#endif +#if HAVE_ARPA_INET_H #include +#endif +#if HAVE_NETINET_TCP_H #include #endif - #if HAVE_SYS_SOCKET_H #include #endif @@ -63,7 +68,7 @@ #include #include -#include +#include static int tcpip_close(COMSTACK h); static int tcpip_put(COMSTACK h, char *buf, int size); @@ -260,7 +265,7 @@ COMSTACK yaz_tcpip_create(int s, int flags, int protocol, static void tcpip_create_cred(COMSTACK cs) { tcpip_state *sp = (tcpip_state *) cs->cprivate; - sp->cred_ptr = xmalloc(sizeof(*sp->cred_ptr)); + sp->cred_ptr = (struct tcpip_cred_ptr *) xmalloc(sizeof(*sp->cred_ptr)); sp->cred_ptr->ref = 1; gnutls_certificate_allocate_credentials(&sp->cred_ptr->xcred); } @@ -413,7 +418,6 @@ int tcpip_strtoaddr_ex(const char *str, struct sockaddr_in *add, return 1; } - #if HAVE_GETADDRINFO void *tcpip_straddr(COMSTACK h, const char *str) { @@ -435,7 +439,10 @@ void *tcpip_straddr(COMSTACK h, const char *str) { s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (s != -1) + { + sp->ai = ai; break; + } } if (s == -1) return 0; @@ -599,7 +606,7 @@ int tcpip_rcvconnect(COMSTACK h) tcpip_create_cred(h); gnutls_init(&sp->session, GNUTLS_CLIENT); - gnutls_priority_set_direct(sp->session, "PERFORMANCE", NULL); + gnutls_set_default_priority(sp->session); gnutls_credentials_set (sp->session, GNUTLS_CRD_CERTIFICATE, sp->cred_ptr->xcred); @@ -806,7 +813,11 @@ int tcpip_listen(COMSTACK h, char *raddr, int *addrlen, h->cerrno = CSOUTSTATE; return -1; } +#ifdef WIN32 + h->newfd = accept(h->iofile, 0, 0); +#else h->newfd = accept(h->iofile, (struct sockaddr*)&addr, &len); +#endif if (h->newfd < 0) { if ( @@ -938,8 +949,7 @@ COMSTACK tcpip_accept(COMSTACK h) xfree(state); return 0; } - res = gnutls_priority_set_direct(state->session, - "PERFORMANCE", NULL); + res = gnutls_set_default_priority(state->session); if (res != GNUTLS_E_SUCCESS) { xfree(cnew); @@ -1040,8 +1050,8 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) TRC(fprintf(stderr, "tcpip_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)); + TRC(fprintf(stderr, " %d bytes in altbuf (%p)\n", sp->altlen, + sp->altbuf)); tmpc = *buf; tmpi = *bufsize; *buf = sp->altbuf; @@ -1146,8 +1156,8 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) h->cerrno = CSYSERR; return -1; } - TRC(fprintf(stderr, " Moving %d bytes to altbuf(0x%x)\n", tomove, - (unsigned) sp->altbuf)); + TRC(fprintf(stderr, " Moving %d bytes to altbuf(%p)\n", tomove, + sp->altbuf)); memcpy(sp->altbuf, *buf + berlen, sp->altlen = tomove); } if (berlen < CS_TCPIP_BUFCHUNK - 1) @@ -1171,8 +1181,8 @@ int ssl_get(COMSTACK h, char **buf, int *bufsize) 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)); + TRC(fprintf(stderr, " %d bytes in altbuf (%p)\n", sp->altlen, + sp->altbuf)); tmpc = *buf; tmpi = *bufsize; *buf = sp->altbuf; @@ -1230,8 +1240,8 @@ int ssl_get(COMSTACK h, char **buf, int *bufsize) } 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)); + TRC(fprintf(stderr, " Moving %d bytes to altbuf(%p)\n", tomove, + sp->altbuf)); memcpy(sp->altbuf, *buf + berlen, sp->altlen = tomove); } if (berlen < CS_TCPIP_BUFCHUNK - 1) @@ -1663,6 +1673,7 @@ static int tcpip_get_connect(COMSTACK h, char **buf, int *bufsize) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab