]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Better gnulib module usage.
authorSimon Josefsson <simon@josefsson.org>
Thu, 30 Oct 2008 19:48:19 +0000 (20:48 +0100)
committerSimon Josefsson <simon@josefsson.org>
Thu, 30 Oct 2008 19:48:19 +0000 (20:48 +0100)
configure.ac
lib/gl/Makefile.am
lib/gl/m4/gnulib-cache.m4
lib/gl/m4/gnulib-comp.m4
lib/gl/m4/sockets.m4 [new file with mode: 0644]
lib/gl/sockets.c [new file with mode: 0644]
lib/gl/sockets.h [new file with mode: 0644]
lib/gl/tests/Makefile.am
lib/gl/tests/test-sockets.c [new file with mode: 0644]
lib/gnutls_buffers.c
lib/gnutls_global.c

index dabc9d7376c01681a91e8e2364fc7b45c305ba4a..d3e1b045fd66d5be17462a63516aed73d0eddca9 100644 (file)
@@ -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])
 
index dce95af1db3fa8f2806a902c9e7d8a256e0c8ac2..523703e538d5d95a438445299a23afafe6d76e51 100644 (file)
@@ -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)
index 9b96c216cce0755fe6ef4753b10d7399632d076f..326f6559e98f99adbfbf2cbde26f6310eb4c93e3 100644 (file)
@@ -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
index 37bff464a8462785e4bf35a8d188fd23fb69a83e..7b1404e4af7c79ea2a074a87671c3d6a9f44d079 100644 (file)
@@ -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 (file)
index 0000000..c7bd664
--- /dev/null
@@ -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 (file)
index 0000000..4d03346
--- /dev/null
@@ -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 (file)
index 0000000..d8f25c2
--- /dev/null
@@ -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
index c5d9c184b22c61bcb7f0df42db2b2060c6742a8a..af0783b5621bc3fe12fac868394e77452347624e 100644 (file)
@@ -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 (file)
index 0000000..514409d
--- /dev/null
@@ -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;
+}
index f4d5911d76a3b827edc4aa0a66e16d7e2ac07cac..f8248b8660bd81cb88f7d81c5f701e396e4601a3 100644 (file)
@@ -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 ();
index 6427d1fdc49b15561124e2f1e0568640739b7065..f8cac0cbd874544f3f8135f672e8f6778947b176 100644 (file)
 
 #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);