summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2008-10-30 20:48:19 +0100
committerSimon Josefsson <simon@josefsson.org>2008-10-30 20:48:19 +0100
commitfcf9ef8f0764b1a02d71b97d33f0201e5ef82deb (patch)
tree505eea87b513fa8006271d615b4fe5a93759eed3
parent39d7d21c38b99f5e804f5ef462ebc4a2a316088c (diff)
downloadgnutls-fcf9ef8f0764b1a02d71b97d33f0201e5ef82deb.tar.gz
Better gnulib module usage.
-rw-r--r--configure.ac31
-rw-r--r--lib/gl/Makefile.am8
-rw-r--r--lib/gl/m4/gnulib-cache.m43
-rw-r--r--lib/gl/m4/gnulib-comp.m45
-rw-r--r--lib/gl/m4/sockets.m465
-rw-r--r--lib/gl/sockets.c57
-rw-r--r--lib/gl/sockets.h32
-rw-r--r--lib/gl/tests/Makefile.am9
-rw-r--r--lib/gl/tests/test-sockets.c44
-rw-r--r--lib/gnutls_buffers.c4
-rw-r--r--lib/gnutls_global.c34
11 files changed, 227 insertions, 65 deletions
diff --git a/configure.ac b/configure.ac
index dabc9d7376..d3e1b045fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,15 +104,6 @@ if test $ac_cv_c_compiler_gnu != no; then
_gcc_gnu89_inline=yes, _gcc_gnu89_inline=no)
AC_MSG_RESULT($_gcc_gnu89_inline)
CFLAGS="$_gcc_cflags_save"
-
- AC_MSG_CHECKING([whether we have GNU assembler])
- GAS=`as --version < /dev/null 2>/dev/null | grep GNU`
- if test "$GAS"; then
- AM_CFLAGS="${AM_CFLAGS} -pipe"
- AC_MSG_RESULT(yes)
- else
- AC_MSG_RESULT(no)
- fi
fi
# Needs to be called outside of 'if' clause.
@@ -251,26 +242,6 @@ LIBS=$SAVED_LIBS
AC_MSG_CHECKING([whether to use the included libcfg])
AC_MSG_RESULT($libcfg_enabled)
-# Windows hacks.
-
-AC_DEFINE([WINVER], [0x0501], [Windows 2000 or before not supported.])
-save_LIBS="$LIBS"
-LIBS="$LIBS -lws2_32"
-AC_TRY_LINK([#include <winsock2.h>], [
- WORD wVersionRequested = MAKEWORD(2, 2);
- WSADATA wsaData;
- int err = WSAStartup(wVersionRequested, &wsaData);
- WSACleanup ();], wsastartup=yes, wsastartup=no)
-LIBS="$save_LIBS"
-if test "$wsastartup" = "yes"; then
- AC_DEFINE(HAVE_WINSOCK, 1, [Call WSAStartup in gnutls_global_init])
-fi
-AC_MSG_CHECKING([if we have Windows and WSAStartup/WSACleanup in -lws2_32])
-AC_MSG_RESULT($wsastartup)
-
-dnl Gnulib files
-dnl
-
AC_MSG_RESULT([***
*** Setting up gnulib compatibility files...
])
@@ -282,8 +253,6 @@ AC_MSG_RESULT([***
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
-AC_SUBST(AM_CFLAGS)
-
AC_CONFIG_SUBDIRS([lib])
AC_CONFIG_SUBDIRS([libextra])
diff --git a/lib/gl/Makefile.am b/lib/gl/Makefile.am
index dce95af1db..523703e538 100644
--- a/lib/gl/Makefile.am
+++ b/lib/gl/Makefile.am
@@ -9,7 +9,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=liblgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --lgpl=2 --libtool --macro-prefix=lgl --no-vc-files byteswap c-ctype fseeko func gettext memmem-simple memmove minmax netdb read-file snprintf socklen stdint strcase strverscmp sys_socket sys_stat time_r unistd vasprintf
+# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=liblgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --lgpl=2 --libtool --macro-prefix=lgl --no-vc-files byteswap c-ctype fseeko func gettext memmem-simple memmove minmax netdb read-file snprintf sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r unistd vasprintf
AUTOMAKE_OPTIONS = 1.5 gnits
@@ -279,6 +279,12 @@ EXTRA_liblgnu_la_SOURCES += snprintf.c
## end gnulib module snprintf
+## begin gnulib module sockets
+
+liblgnu_la_SOURCES += sockets.h sockets.c
+
+## end gnulib module sockets
+
## begin gnulib module stdbool
BUILT_SOURCES += $(STDBOOL_H)
diff --git a/lib/gl/m4/gnulib-cache.m4 b/lib/gl/m4/gnulib-cache.m4
index 9b96c216cc..326f6559e9 100644
--- a/lib/gl/m4/gnulib-cache.m4
+++ b/lib/gl/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@
# Specification in the form of a command-line invocation:
-# gnulib-tool --import --dir=. --local-dir=gl/override --lib=liblgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --lgpl=2 --libtool --macro-prefix=lgl --no-vc-files byteswap c-ctype fseeko func gettext memmem-simple memmove minmax netdb read-file snprintf socklen stdint strcase strverscmp sys_socket sys_stat time_r unistd vasprintf
+# gnulib-tool --import --dir=. --local-dir=gl/override --lib=liblgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --lgpl=2 --libtool --macro-prefix=lgl --no-vc-files byteswap c-ctype fseeko func gettext memmem-simple memmove minmax netdb read-file snprintf sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r unistd vasprintf
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([gl/override])
@@ -31,6 +31,7 @@ gl_MODULES([
netdb
read-file
snprintf
+ sockets
socklen
stdint
strcase
diff --git a/lib/gl/m4/gnulib-comp.m4 b/lib/gl/m4/gnulib-comp.m4
index 37bff464a8..7b1404e4af 100644
--- a/lib/gl/m4/gnulib-comp.m4
+++ b/lib/gl/m4/gnulib-comp.m4
@@ -69,6 +69,7 @@ AC_DEFUN([lgl_INIT],
gl_SIZE_MAX
gl_FUNC_SNPRINTF
gl_STDIO_MODULE_INDICATOR([snprintf])
+ gl_SOCKETS
gl_TYPE_SOCKLEN_T
AM_STDBOOL_H
gl_STDINT_H
@@ -257,6 +258,8 @@ AC_DEFUN([lgl_FILE_LIST], [
lib/realloc.c
lib/size_max.h
lib/snprintf.c
+ lib/sockets.c
+ lib/sockets.h
lib/stdbool.in.h
lib/stdint.in.h
lib/stdio-impl.h
@@ -324,6 +327,7 @@ AC_DEFUN([lgl_FILE_LIST], [
m4/realloc.m4
m4/size_max.m4
m4/snprintf.m4
+ m4/sockets.m4
m4/socklen.m4
m4/sockpfaf.m4
m4/stdbool.m4
@@ -363,6 +367,7 @@ AC_DEFUN([lgl_FILE_LIST], [
tests/test-netdb.c
tests/test-read-file.c
tests/test-snprintf.c
+ tests/test-sockets.c
tests/test-stdbool.c
tests/test-stdint.c
tests/test-stdio.c
diff --git a/lib/gl/m4/sockets.m4 b/lib/gl/m4/sockets.m4
new file mode 100644
index 0000000000..c7bd6646a6
--- /dev/null
+++ b/lib/gl/m4/sockets.m4
@@ -0,0 +1,65 @@
+# sockets.m4 serial 2
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_SOCKETS],
+[
+ gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H
+ LIBSOCKET=
+ if test $HAVE_WINSOCK2_H = 1; then
+ dnl Native Windows API (not Cygwin).
+ AC_CACHE_CHECK([if we need to call WSAStartup in winsock2.h and -lws2_32],
+ [gl_cv_func_wsastartup], [
+ gl_save_LIBS="$LIBS"
+ LIBS="$LIBS -lws2_32"
+ AC_TRY_LINK([
+#ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif], [
+ WORD wVersionRequested = MAKEWORD(1, 1);
+ WSADATA wsaData;
+ int err = WSAStartup(wVersionRequested, &wsaData);
+ WSACleanup ();],
+ gl_cv_func_wsastartup=yes, gl_cv_func_wsastartup=no)
+ LIBS="$gl_save_LIBS"
+ ])
+ if test "$gl_cv_func_wsastartup" = "yes"; then
+ AC_DEFINE([WINDOWS_SOCKETS], 1, [Define if WSAStartup is needed.])
+ LIBSOCKET='-lws2_32'
+ fi
+ else
+ dnl Unix API.
+ dnl Solaris has most socket functions in libsocket.
+ AC_CACHE_CHECK([whether setsockopt requires -lsocket], [gl_cv_lib_socket], [
+ gl_cv_lib_socket=no
+ AC_TRY_LINK([extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();], [setsockopt();],
+ [],
+ [gl_save_LIBS="$LIBS"
+ LIBS="$LIBS -lsocket"
+ AC_TRY_LINK([extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();], [setsockopt();],
+ [gl_cv_lib_socket=yes])
+ LIBS="$gl_save_LIBS"
+ ])
+ ])
+ if test $gl_cv_lib_socket = yes; then
+ LIBSOCKET='-lsocket'
+ fi
+ fi
+ AC_SUBST([LIBSOCKET])
+ gl_PREREQ_SOCKETS
+])
+
+# Prerequisites of lib/sockets.c.
+AC_DEFUN([gl_PREREQ_SOCKETS], [
+ :
+])
diff --git a/lib/gl/sockets.c b/lib/gl/sockets.c
new file mode 100644
index 0000000000..4d03346e64
--- /dev/null
+++ b/lib/gl/sockets.c
@@ -0,0 +1,57 @@
+/* sockets.c --- wrappers for Windows socket functions
+
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Simon Josefsson */
+
+#include <config.h>
+
+/* This includes winsock2.h on MinGW. */
+#include <sys/socket.h>
+
+#include "sockets.h"
+
+int
+gl_sockets_startup (int version)
+{
+#if WINDOWS_SOCKETS
+ WSADATA data;
+ int err;
+
+ err = WSAStartup (version, &data);
+ if (err != 0)
+ return 1;
+
+ if (data.wVersion < version)
+ return 2;
+#endif
+
+ return 0;
+}
+
+int
+gl_sockets_cleanup (void)
+{
+#if WINDOWS_SOCKETS
+ int err;
+
+ err = WSACleanup ();
+ if (err != 0)
+ return 1;
+#endif
+
+ return 0;
+}
diff --git a/lib/gl/sockets.h b/lib/gl/sockets.h
new file mode 100644
index 0000000000..d8f25c238d
--- /dev/null
+++ b/lib/gl/sockets.h
@@ -0,0 +1,32 @@
+/* sockets.h - wrappers for Windows socket functions
+
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Simon Josefsson */
+
+#ifndef SOCKETS_H
+# define SOCKETS_H 1
+
+#define SOCKETS_1_0 0x100
+#define SOCKETS_1_1 0x101
+#define SOCKETS_2_0 0x200
+#define SOCKETS_2_1 0x201
+#define SOCKETS_2_2 0x202
+
+int gl_sockets_startup (int version);
+int gl_sockets_cleanup (void);
+
+#endif
diff --git a/lib/gl/tests/Makefile.am b/lib/gl/tests/Makefile.am
index c5d9c184b2..af0783b562 100644
--- a/lib/gl/tests/Makefile.am
+++ b/lib/gl/tests/Makefile.am
@@ -153,6 +153,15 @@ EXTRA_DIST += test-snprintf.c
## end gnulib module snprintf-tests
+## begin gnulib module sockets-tests
+
+TESTS += test-sockets
+check_PROGRAMS += test-sockets
+test_sockets_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-sockets.c
+
+## end gnulib module sockets-tests
+
## begin gnulib module stdbool-tests
TESTS += test-stdbool
diff --git a/lib/gl/tests/test-sockets.c b/lib/gl/tests/test-sockets.c
new file mode 100644
index 0000000000..514409d95b
--- /dev/null
+++ b/lib/gl/tests/test-sockets.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2008 Free Software Foundation
+ * Written by Simon Josefsson.
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "sockets.h"
+
+int
+main (int argc, char *argv[])
+{
+ int err;
+
+ err = gl_sockets_startup (SOCKETS_1_1);
+ if (err != 0)
+ {
+ printf ("wsastartup failed %d\n", err);
+ return 1;
+ }
+
+ err = gl_sockets_cleanup ();
+ if (err != 0)
+ {
+ printf ("wsacleanup failed %d\n", err);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c
index f4d5911d76..f8248b8660 100644
--- a/lib/gnutls_buffers.c
+++ b/lib/gnutls_buffers.c
@@ -313,7 +313,7 @@ _gnutls_read (gnutls_session_t session, void *iptr,
{
i = recv (GNUTLS_POINTER_TO_INT (fd), &ptr[sizeOfPtr - left],
left, flags);
-#if HAVE_WINSOCK
+#if HAVE_WINSOCK2_H
if (i < 0)
{
int tmperr = WSAGetLastError ();
@@ -779,7 +779,7 @@ _gnutls_io_write_buffered (gnutls_session_t session,
if (session->internals._gnutls_push_func == NULL)
{
i = send (GNUTLS_POINTER_TO_INT (fd), &ptr[n - left], left, 0);
-#if HAVE_WINSOCK
+#if HAVE_WINSOCK2_H
if (i < 0)
{
int tmperr = WSAGetLastError ();
diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index 6427d1fdc4..f8cac0cbd8 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -31,10 +31,7 @@
#include <gnutls_extensions.h> /* for _gnutls_ext_init */
-#ifdef HAVE_WINSOCK
-# include <winsock2.h>
-#endif
-
+#include "sockets.h"
#include "gettext.h"
#define gnutls_log_func LOG_FUNC
@@ -198,29 +195,8 @@ gnutls_global_init (void)
if (_gnutls_init++)
goto out;
-#if HAVE_WINSOCK
- {
- WORD requested;
- WSADATA data;
- int err;
-
- requested = MAKEWORD (1, 1);
- err = WSAStartup (requested, &data);
- if (err != 0)
- {
- _gnutls_debug_log ("WSAStartup failed: %d.\n", err);
- return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
- }
-
- if (data.wVersion < requested)
- {
- _gnutls_debug_log ("WSAStartup version check failed (%d < %d).\n",
- data.wVersion, requested);
- WSACleanup ();
- return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
- }
- }
-#endif
+ if (gl_sockets_startup (SOCKETS_1_1))
+ return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
bindtextdomain (PACKAGE, LOCALEDIR);
@@ -318,9 +294,7 @@ gnutls_global_deinit (void)
{
if (_gnutls_init == 1)
{
-#if HAVE_WINSOCK
- WSACleanup ();
-#endif
+ gl_sockets_cleanup ();
_gnutls_rnd_deinit ();
asn1_delete_structure (&_gnutls_gnutls_asn);
asn1_delete_structure (&_gnutls_pkix1_asn);