diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-11-17 21:15:50 +0100 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-11-17 21:15:50 +0100 |
commit | 73ed8d8b99030c336ec1c95291b5d5571eecbbd0 (patch) | |
tree | cba3be1d437b5eb7550848a9f659be1c60b9de6c | |
parent | 31a5679d33dbb2d4b677debc13860d9acd387c47 (diff) | |
download | gnutls-73ed8d8b99030c336ec1c95291b5d5571eecbbd0.tar.gz |
Use more warnings. Fix many warnings.
53 files changed, 515 insertions, 742 deletions
diff --git a/configure.ac b/configure.ac index 657790a81e..89858f7476 100644 --- a/configure.ac +++ b/configure.ac @@ -42,7 +42,8 @@ if test "x$GAA" = "x"; then AC_MSG_WARN([[*** *** GAA was not found. It is only needed if you wish to modify *** the source code or command-line description files. In this case, -*** you may want to get it from http://gaa.sourceforge.net/ +*** you may want to get it from http://gaa.sourceforge.net/ and +*** read doc/README.gaa. ***]]) fi AM_CONDITIONAL(HAVE_GCC, test "x$GCC" = "xyes") @@ -172,12 +173,6 @@ AC_PROG_LIBTOOL gl_INIT -# These are additional warnings we could enable: -# -# -Wshadow -Wunsafe-loop-optimizations Wcast-qual Wlogical-op -# -Waggregate-return Wmissing-prototypes -Wmissing-declarations -# -Wmissing-noreturn -Wmissing-format-attribute Wredundant-decls -Wvla -# # These are warnings we have tried but have turned out not to be useful: # # -Wtraditional: warns on #elif which we use often @@ -194,17 +189,47 @@ gl_INIT # -Wno-pointer-sign: too many warnings for now # -Wno-unused-parameter: added because -Wunused cause too many warns -BASICS="-Wall -W" - -ADDITIONAL="-Wchar-subscripts -Wformat-security -Wnonnull -Winit-self -Wmissing-include-dirs -Wunused -Wfloat-equal -Wdeclaration-after-statement -Wpointer-arith -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wpacked -Wnested-externs -Winline -Wvolatile-register-var -Wdisabled-optimization -Wstack-protector -Woverlength-strings" - -REMOVE="-Wno-pointer-sign -Wno-unused-parameter" - -for w in $BASICS $ADDITIONAL $REMOVE; do +gl_WARN_SUPPORTED([WARNINGS]) + +# Useless warnings. +USELESS_WARNINGS=" \ + -Wc++-compat \ + -Wsystem-headers \ + -Wundef \ + -Wtraditional \ + -Wtraditional-conversion" +gl_WARN_COMPLEMENT(WARNINGS, [$WARNINGS], [$USELESS_WARNINGS]) +# Review these from time to time. +USELESS_WARNINGS=" \ + -Wcast-qual \ + -Wlogical-op \ + -Waggregate-return \ + -Wshadow \ + -Wswitch-default \ + -Wswitch-enum \ + -Wconversion \ + -Wsign-conversion \ + -Wold-style-definition \ + -Wpadded \ + -Wsign-compare \ + -Wunreachable-code \ + -Wformat-y2k \ + -Wunsafe-loop-optimizations \ + -Wstrict-overflow" +gl_WARN_COMPLEMENT(WARNINGS, [$WARNINGS], [$USELESS_WARNINGS]) + +for w in $WARNINGS; do gl_WARN_ADD([$w]) done + +gl_WARN_ADD([-Wno-missing-field-initializers]) +gl_WARN_ADD([-Wno-pointer-sign]) +gl_WARN_ADD([-Wno-unused-parameter]) +gl_WARN_ADD([-fdiagnostics-show-option]) export WARN_CFLAGS +gl_WARN_ADD([]) + AC_CONFIG_SUBDIRS([lib]) AC_CONFIG_SUBDIRS([libextra]) diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am index ecba23d680..3ba158f8d3 100644 --- a/doc/examples/Makefile.am +++ b/doc/examples/Makefile.am @@ -70,5 +70,6 @@ endif noinst_LTLIBRARIES = libexamples.la -libexamples_la_SOURCES = ex-alert.c ex-pkcs12.c ex-rfc2818.c \ - ex-session-info.c ex-x509-info.c ex-verify.c tcp.c +libexamples_la_SOURCES = examples.h ex-alert.c ex-pkcs12.c \ + ex-rfc2818.c ex-session-info.c ex-x509-info.c ex-verify.c \ + tcp.c diff --git a/doc/examples/ex-alert.c b/doc/examples/ex-alert.c index 7f5829925c..ba708a366c 100644 --- a/doc/examples/ex-alert.c +++ b/doc/examples/ex-alert.c @@ -1,4 +1,4 @@ -/* Copyright 2007 Free Software Foundation +/* Copyright 2007, 2008 Free Software Foundation * * Copying and distribution of this file, with or without modification, * are permitted in any medium without royalty provided the copyright @@ -13,6 +13,8 @@ #include <stdlib.h> #include <gnutls/gnutls.h> +#include "examples.h" + /* This function will check whether the given return code from * a gnutls function (recv/send), is an alert, and will print * that alert. diff --git a/doc/examples/ex-client-psk.c b/doc/examples/ex-client-psk.c index dc1b0f6a12..9d62ccfae0 100644 --- a/doc/examples/ex-client-psk.c +++ b/doc/examples/ex-client-psk.c @@ -36,7 +36,7 @@ main (void) char buffer[MAX_BUF + 1]; const char *err; gnutls_psk_client_credentials_t pskcred; - const gnutls_datum_t key = { "DEADBEEF", 8 }; + const gnutls_datum_t key = { (char*) "DEADBEEF", 8 }; gnutls_global_init (); diff --git a/doc/examples/ex-pkcs12.c b/doc/examples/ex-pkcs12.c index b017c85a45..23363c78d4 100644 --- a/doc/examples/ex-pkcs12.c +++ b/doc/examples/ex-pkcs12.c @@ -1,4 +1,4 @@ -/* Copyright 2007 Free Software Foundation +/* Copyright 2007, 2008 Free Software Foundation * * Copying and distribution of this file, with or without modification, * are permitted in any medium without royalty provided the copyright @@ -14,6 +14,8 @@ #include <gnutls/gnutls.h> #include <gnutls/pkcs12.h> +#include "examples.h" + #define OUTFILE "out.p12" /* This function will write a pkcs12 structure into a file. @@ -36,7 +38,7 @@ write_pkcs12 (const gnutls_datum_t * cert, /* A good idea might be to use gnutls_x509_privkey_get_key_id() * to obtain a unique ID. */ - gnutls_datum_t key_id = { "\x00\x00\x07", 3 }; + gnutls_datum_t key_id = { (char*) "\x00\x00\x07", 3 }; gnutls_global_init (); diff --git a/doc/examples/ex-rfc2818.c b/doc/examples/ex-rfc2818.c index 49fd7b608d..010fb30d67 100644 --- a/doc/examples/ex-rfc2818.c +++ b/doc/examples/ex-rfc2818.c @@ -1,4 +1,4 @@ -/* Copyright 2007 Free Software Foundation +/* Copyright 2007, 2008 Free Software Foundation * * Copying and distribution of this file, with or without modification, * are permitted in any medium without royalty provided the copyright @@ -13,6 +13,8 @@ #include <gnutls/gnutls.h> #include <gnutls/x509.h> +#include "examples.h" + /* This function will try to verify the peer's certificate, and * also check if the hostname matches, and the activation, expiration dates. */ diff --git a/doc/examples/ex-session-info.c b/doc/examples/ex-session-info.c index 6f1d07abaa..3ddbd3b38d 100644 --- a/doc/examples/ex-session-info.c +++ b/doc/examples/ex-session-info.c @@ -14,7 +14,7 @@ #include <gnutls/gnutls.h> #include <gnutls/x509.h> -extern void print_x509_certificate_info (gnutls_session_t); +#include "examples.h" /* This function will print some details of the * given session. diff --git a/doc/examples/ex-verify.c b/doc/examples/ex-verify.c index e9337213bc..ab3f2c6dad 100644 --- a/doc/examples/ex-verify.c +++ b/doc/examples/ex-verify.c @@ -1,4 +1,4 @@ -/* Copyright 2007 Free Software Foundation +/* Copyright 2007, 2008 Free Software Foundation * * Copying and distribution of this file, with or without modification, * are permitted in any medium without royalty provided the copyright @@ -14,6 +14,8 @@ #include <gnutls/gnutls.h> #include <gnutls/x509.h> +#include "examples.h" + /* All the available CRLs */ gnutls_x509_crl_t *crl_list; diff --git a/doc/examples/ex-x509-info.c b/doc/examples/ex-x509-info.c index d1433ab559..1fe3684100 100644 --- a/doc/examples/ex-x509-info.c +++ b/doc/examples/ex-x509-info.c @@ -14,6 +14,8 @@ #include <gnutls/gnutls.h> #include <gnutls/x509.h> +#include "examples.h" + static const char * bin2hex (const void *bin, size_t bin_size) { diff --git a/doc/examples/tcp.c b/doc/examples/tcp.c index ec390e623e..876e706057 100644 --- a/doc/examples/tcp.c +++ b/doc/examples/tcp.c @@ -1,4 +1,4 @@ -/* Copyright 2007 Free Software Foundation +/* Copyright 2007, 2008 Free Software Foundation * * Copying and distribution of this file, with or without modification, * are permitted in any medium without royalty provided the copyright @@ -20,6 +20,10 @@ #define SA struct sockaddr +/* tcp.c */ +int tcp_connect (void); +void tcp_close (int sd); + /* Connects to the peer and returns a socket * descriptor. */ diff --git a/gl/gettext.h b/gl/gettext.h index 763dd3c147..daaaa97576 100644 --- a/gl/gettext.h +++ b/gl/gettext.h @@ -162,109 +162,4 @@ npgettext_aux (const char *domain, return translation; } -/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID - can be arbitrary expressions. But for string literals these macros are - less efficient than those above. */ - -#include <string.h> - -#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ - (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ - /* || __STDC_VERSION__ >= 199901L */ ) - -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS -#include <stdlib.h> -#endif - -#define pgettext_expr(Msgctxt, Msgid) \ - dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) -#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ - dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -dcpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - int category) -{ - size_t msgctxt_len = strlen (msgctxt) + 1; - size_t msgid_len = strlen (msgid) + 1; - const char *translation; -#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; -#else - char buf[1024]; - char *msg_ctxt_id = - (msgctxt_len + msgid_len <= sizeof (buf) - ? buf - : (char *) malloc (msgctxt_len + msgid_len)); - if (msg_ctxt_id != NULL) -#endif - { - memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); - msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dcgettext (domain, msg_ctxt_id, category); -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - if (msg_ctxt_id != buf) - free (msg_ctxt_id); -#endif - if (translation != msg_ctxt_id) - return translation; - } - return msgid; -} - -#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ - dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) -#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ - dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -dcnpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - const char *msgid_plural, unsigned long int n, - int category) -{ - size_t msgctxt_len = strlen (msgctxt) + 1; - size_t msgid_len = strlen (msgid) + 1; - const char *translation; -#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; -#else - char buf[1024]; - char *msg_ctxt_id = - (msgctxt_len + msgid_len <= sizeof (buf) - ? buf - : (char *) malloc (msgctxt_len + msgid_len)); - if (msg_ctxt_id != NULL) -#endif - { - memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); - msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - if (msg_ctxt_id != buf) - free (msg_ctxt_id); -#endif - if (!(translation == msg_ctxt_id || translation == msgid_plural)) - return translation; - } - return (n == 1 ? msgid : msgid_plural); -} - #endif /* _LIBGETTEXT_H */ diff --git a/gl/override/lib/gettext.h.diff b/gl/override/lib/gettext.h.diff new file mode 100644 index 0000000000..fcd13cb8b4 --- /dev/null +++ b/gl/override/lib/gettext.h.diff @@ -0,0 +1,112 @@ +--- gl/gettext.h.orig 2008-11-17 17:12:20.000000000 +0100 ++++ gl/gettext.h 2008-11-17 17:12:29.000000000 +0100 +@@ -162,109 +162,4 @@ + return translation; + } + +-/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID +- can be arbitrary expressions. But for string literals these macros are +- less efficient than those above. */ +- +-#include <string.h> +- +-#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ +- (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ +- /* || __STDC_VERSION__ >= 199901L */ ) +- +-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +-#include <stdlib.h> +-#endif +- +-#define pgettext_expr(Msgctxt, Msgid) \ +- dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) +-#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ +- dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) +- +-#ifdef __GNUC__ +-__inline +-#else +-#ifdef __cplusplus +-inline +-#endif +-#endif +-static const char * +-dcpgettext_expr (const char *domain, +- const char *msgctxt, const char *msgid, +- int category) +-{ +- size_t msgctxt_len = strlen (msgctxt) + 1; +- size_t msgid_len = strlen (msgid) + 1; +- const char *translation; +-#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +- char msg_ctxt_id[msgctxt_len + msgid_len]; +-#else +- char buf[1024]; +- char *msg_ctxt_id = +- (msgctxt_len + msgid_len <= sizeof (buf) +- ? buf +- : (char *) malloc (msgctxt_len + msgid_len)); +- if (msg_ctxt_id != NULL) +-#endif +- { +- memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); +- msg_ctxt_id[msgctxt_len - 1] = '\004'; +- memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); +- translation = dcgettext (domain, msg_ctxt_id, category); +-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +- if (msg_ctxt_id != buf) +- free (msg_ctxt_id); +-#endif +- if (translation != msg_ctxt_id) +- return translation; +- } +- return msgid; +-} +- +-#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ +- dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) +-#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ +- dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) +- +-#ifdef __GNUC__ +-__inline +-#else +-#ifdef __cplusplus +-inline +-#endif +-#endif +-static const char * +-dcnpgettext_expr (const char *domain, +- const char *msgctxt, const char *msgid, +- const char *msgid_plural, unsigned long int n, +- int category) +-{ +- size_t msgctxt_len = strlen (msgctxt) + 1; +- size_t msgid_len = strlen (msgid) + 1; +- const char *translation; +-#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +- char msg_ctxt_id[msgctxt_len + msgid_len]; +-#else +- char buf[1024]; +- char *msg_ctxt_id = +- (msgctxt_len + msgid_len <= sizeof (buf) +- ? buf +- : (char *) malloc (msgctxt_len + msgid_len)); +- if (msg_ctxt_id != NULL) +-#endif +- { +- memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); +- msg_ctxt_id[msgctxt_len - 1] = '\004'; +- memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); +- translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); +-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +- if (msg_ctxt_id != buf) +- free (msg_ctxt_id); +-#endif +- if (!(translation == msg_ctxt_id || translation == msgid_plural)) +- return translation; +- } +- return (n == 1 ? msgid : msgid_plural); +-} +- + #endif /* _LIBGETTEXT_H */ diff --git a/lib/gl/gettext.h b/lib/gl/gettext.h index bd214d5cec..a8ca5a4c21 100644 --- a/lib/gl/gettext.h +++ b/lib/gl/gettext.h @@ -162,109 +162,4 @@ npgettext_aux (const char *domain, return translation; } -/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID - can be arbitrary expressions. But for string literals these macros are - less efficient than those above. */ - -#include <string.h> - -#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ - (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ - /* || __STDC_VERSION__ >= 199901L */ ) - -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS -#include <stdlib.h> -#endif - -#define pgettext_expr(Msgctxt, Msgid) \ - dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) -#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ - dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -dcpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - int category) -{ - size_t msgctxt_len = strlen (msgctxt) + 1; - size_t msgid_len = strlen (msgid) + 1; - const char *translation; -#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; -#else - char buf[1024]; - char *msg_ctxt_id = - (msgctxt_len + msgid_len <= sizeof (buf) - ? buf - : (char *) malloc (msgctxt_len + msgid_len)); - if (msg_ctxt_id != NULL) -#endif - { - memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); - msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dcgettext (domain, msg_ctxt_id, category); -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - if (msg_ctxt_id != buf) - free (msg_ctxt_id); -#endif - if (translation != msg_ctxt_id) - return translation; - } - return msgid; -} - -#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ - dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) -#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ - dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -dcnpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - const char *msgid_plural, unsigned long int n, - int category) -{ - size_t msgctxt_len = strlen (msgctxt) + 1; - size_t msgid_len = strlen (msgid) + 1; - const char *translation; -#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; -#else - char buf[1024]; - char *msg_ctxt_id = - (msgctxt_len + msgid_len <= sizeof (buf) - ? buf - : (char *) malloc (msgctxt_len + msgid_len)); - if (msg_ctxt_id != NULL) -#endif - { - memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); - msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - if (msg_ctxt_id != buf) - free (msg_ctxt_id); -#endif - if (!(translation == msg_ctxt_id || translation == msgid_plural)) - return translation; - } - return (n == 1 ? msgid : msgid_plural); -} - #endif /* _LIBGETTEXT_H */ diff --git a/lib/gl/override/lib/gettext.h.diff b/lib/gl/override/lib/gettext.h.diff new file mode 100644 index 0000000000..ec8f03fe78 --- /dev/null +++ b/lib/gl/override/lib/gettext.h.diff @@ -0,0 +1,112 @@ +--- lib/gl/gettext.h.orig 2008-11-17 17:11:58.000000000 +0100 ++++ lib/gl/gettext.h 2008-11-17 17:12:03.000000000 +0100 +@@ -162,109 +162,4 @@ + return translation; + } + +-/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID +- can be arbitrary expressions. But for string literals these macros are +- less efficient than those above. */ +- +-#include <string.h> +- +-#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ +- (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ +- /* || __STDC_VERSION__ >= 199901L */ ) +- +-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +-#include <stdlib.h> +-#endif +- +-#define pgettext_expr(Msgctxt, Msgid) \ +- dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) +-#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ +- dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) +- +-#ifdef __GNUC__ +-__inline +-#else +-#ifdef __cplusplus +-inline +-#endif +-#endif +-static const char * +-dcpgettext_expr (const char *domain, +- const char *msgctxt, const char *msgid, +- int category) +-{ +- size_t msgctxt_len = strlen (msgctxt) + 1; +- size_t msgid_len = strlen (msgid) + 1; +- const char *translation; +-#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +- char msg_ctxt_id[msgctxt_len + msgid_len]; +-#else +- char buf[1024]; +- char *msg_ctxt_id = +- (msgctxt_len + msgid_len <= sizeof (buf) +- ? buf +- : (char *) malloc (msgctxt_len + msgid_len)); +- if (msg_ctxt_id != NULL) +-#endif +- { +- memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); +- msg_ctxt_id[msgctxt_len - 1] = '\004'; +- memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); +- translation = dcgettext (domain, msg_ctxt_id, category); +-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +- if (msg_ctxt_id != buf) +- free (msg_ctxt_id); +-#endif +- if (translation != msg_ctxt_id) +- return translation; +- } +- return msgid; +-} +- +-#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ +- dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) +-#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ +- dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) +- +-#ifdef __GNUC__ +-__inline +-#else +-#ifdef __cplusplus +-inline +-#endif +-#endif +-static const char * +-dcnpgettext_expr (const char *domain, +- const char *msgctxt, const char *msgid, +- const char *msgid_plural, unsigned long int n, +- int category) +-{ +- size_t msgctxt_len = strlen (msgctxt) + 1; +- size_t msgid_len = strlen (msgid) + 1; +- const char *translation; +-#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +- char msg_ctxt_id[msgctxt_len + msgid_len]; +-#else +- char buf[1024]; +- char *msg_ctxt_id = +- (msgctxt_len + msgid_len <= sizeof (buf) +- ? buf +- : (char *) malloc (msgctxt_len + msgid_len)); +- if (msg_ctxt_id != NULL) +-#endif +- { +- memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); +- msg_ctxt_id[msgctxt_len - 1] = '\004'; +- memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); +- translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); +-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS +- if (msg_ctxt_id != buf) +- free (msg_ctxt_id); +-#endif +- if (!(translation == msg_ctxt_id || translation == msgid_plural)) +- return translation; +- } +- return (n == 1 ? msgid : msgid_plural); +-} +- + #endif /* _LIBGETTEXT_H */ diff --git a/lib/gnutls_hash_int.c b/lib/gnutls_hash_int.c index 5ae4e6b1eb..e55ae541e2 100644 --- a/lib/gnutls_hash_int.c +++ b/lib/gnutls_hash_int.c @@ -531,9 +531,9 @@ ssl3_md5 (int i, opaque * secret, int secret_len, } int -_gnutls_ssl3_hash_md5 (void *first, int first_len, - void *second, int second_len, int ret_len, - opaque * ret) +_gnutls_ssl3_hash_md5 (const void *first, int first_len, + const void *second, int second_len, + int ret_len, opaque * ret) { opaque digest[MAX_HASH_SIZE]; digest_hd_st td; diff --git a/lib/gnutls_hash_int.h b/lib/gnutls_hash_int.h index 8606642e43..8017d12f9a 100644 --- a/lib/gnutls_hash_int.h +++ b/lib/gnutls_hash_int.h @@ -83,8 +83,9 @@ int _gnutls_hash_fast( gnutls_digest_algorithm_t algorithm, int _gnutls_ssl3_generate_random (void *secret, int secret_len, void *rnd, int random_len, int bytes, opaque * ret); -int _gnutls_ssl3_hash_md5 (void *first, int first_len, void *second, - int second_len, int ret_len, opaque * ret); +int _gnutls_ssl3_hash_md5 (const void *first, int first_len, + const void *second, int second_len, + int ret_len, opaque * ret); void _gnutls_mac_deinit_ssl3_handshake (digest_hd_st* handle, void *digest, opaque * key, uint32_t key_size); diff --git a/lib/gnutls_state.c b/lib/gnutls_state.c index e42d2f66c4..3817ccbbc6 100644 --- a/lib/gnutls_state.c +++ b/lib/gnutls_state.c @@ -44,6 +44,15 @@ #include <gnutls_algorithms.h> #include <gnutls_rsa_export.h> +/* These should really be static, but src/tests.c calls them. Make + them public functions? */ +void +_gnutls_record_set_default_version (gnutls_session_t session, + unsigned char major, unsigned char minor); +void +_gnutls_rsa_pms_set_version (gnutls_session_t session, + unsigned char major, unsigned char minor); + void _gnutls_session_cert_type_set (gnutls_session_t session, gnutls_certificate_type_t ct) diff --git a/lib/gnutls_str.h b/lib/gnutls_str.h index b5eb31948c..6b84fcae64 100644 --- a/lib/gnutls_str.h +++ b/lib/gnutls_str.h @@ -55,7 +55,17 @@ int _gnutls_string_copy_str (gnutls_string * dest, const char *src); int _gnutls_string_append_str (gnutls_string *, const char *str); int _gnutls_string_append_data (gnutls_string *, const void *data, size_t data_size); -int _gnutls_string_append_printf (gnutls_string * dest, const char *fmt, ...); + + +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# define __attribute__(Spec) /* empty */ +# endif +#endif + +int _gnutls_string_append_printf (gnutls_string * dest, const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); typedef gnutls_string gnutls_buffer; diff --git a/lib/openpgp/output.c b/lib/openpgp/output.c index 027f27ce06..617cf77e83 100644 --- a/lib/openpgp/output.c +++ b/lib/openpgp/output.c @@ -186,9 +186,9 @@ print_key_times (gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) struct tm t; if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); + addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); else if (strftime (s, max, "%a %b %e %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); + addf (str, "error: strftime (%ld)\n", (unsigned long) tim); else addf (str, _("\t\tCreation: %s\n"), s); } @@ -204,14 +204,14 @@ print_key_times (gnutls_string * str, gnutls_openpgp_crt_t cert, int idx) if (tim == 0) { - addf (str, _("\t\tExpiration: Never\n"), s); + addf (str, _("\t\tExpiration: Never\n")); } else { if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); + addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); else if (strftime (s, max, "%a %b %e %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); + addf (str, "error: strftime (%ld)\n", (unsigned long) tim); else addf (str, _("\t\tExpiration: %s\n"), s); } diff --git a/lib/x509/Makefile.am b/lib/x509/Makefile.am index d0337b2459..42039db7c9 100644 --- a/lib/x509/Makefile.am +++ b/lib/x509/Makefile.am @@ -18,8 +18,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA +AM_CFLAGS = $(WARN_CFLAGS) AM_CPPFLAGS = \ - $(WARN_CFLAGS) \ -I$(srcdir)/../gl \ -I$(builddir)/../gl \ -I$(srcdir)/../includes \ diff --git a/lib/x509/dn.c b/lib/x509/dn.c index c8d99594a0..e714b3298e 100644 --- a/lib/x509/dn.c +++ b/lib/x509/dn.c @@ -673,7 +673,7 @@ _gnutls_x509_encode_and_write_attribute (const char *given_oid, if ((result = _gnutls_x509_oid_data_choice (given_oid)) > 0) { - char *string_type; + const char *string_type; int i; string_type = "printableString"; diff --git a/lib/x509/output.c b/lib/x509/output.c index 08f51f3339..a8e40c94be 100644 --- a/lib/x509/output.c +++ b/lib/x509/output.c @@ -41,7 +41,7 @@ #define addf _gnutls_string_append_printf #define adds _gnutls_string_append_str -#define ERROR_STR "(error)" +#define ERROR_STR (char*) "(error)" static void hexdump (gnutls_string * str, const char *data, size_t len, const char *spc) @@ -940,9 +940,9 @@ print_cert (gnutls_string * str, gnutls_x509_crt_t cert, int notsigned) struct tm t; if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); + addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); else if (strftime (s, max, "%a %b %d %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); + addf (str, "error: strftime (%ld)\n", (unsigned long) tim); else addf (str, _("\t\tNot Before: %s\n"), s); } @@ -954,9 +954,9 @@ print_cert (gnutls_string * str, gnutls_x509_crt_t cert, int notsigned) struct tm t; if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); + addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); else if (strftime (s, max, "%a %b %d %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); + addf (str, "error: strftime (%ld)\n", (unsigned long) tim); else addf (str, _("\t\tNot After: %s\n"), s); } @@ -1233,9 +1233,9 @@ print_oneline (gnutls_string * str, gnutls_x509_crt_t cert) struct tm t; if (gmtime_r (&tim, &t) == NULL) - addf (str, "unknown activation (%d), ", t); + addf (str, "unknown activation (%ld), ", (unsigned long) tim); else if (strftime (s, max, "%Y-%m-%d %H:%M:%S UTC", &t) == 0) - addf (str, "failed activation (%d), ", t); + addf (str, "failed activation (%ld), ", (unsigned long) tim); else addf (str, "activated `%s', ", s); } @@ -1247,9 +1247,9 @@ print_oneline (gnutls_string * str, gnutls_x509_crt_t cert) struct tm t; if (gmtime_r (&tim, &t) == NULL) - addf (str, "unknown expiry (%d), ", t); + addf (str, "unknown expiry (%ld), ", (unsigned long) tim); else if (strftime (s, max, "%Y-%m-%d %H:%M:%S UTC", &t) == 0) - addf (str, "failed expiry (%d), ", t); + addf (str, "failed expiry (%ld), ", (unsigned long) tim); else addf (str, "expires `%s', ", s); } @@ -1405,9 +1405,9 @@ print_crl (gnutls_string * str, gnutls_x509_crl_t crl, int notsigned) struct tm t; if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); + addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); else if (strftime (s, max, "%a %b %d %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); + addf (str, "error: strftime (%ld)\n", (unsigned long) tim); else addf (str, _("\t\tIssued: %s\n"), s); } @@ -1421,9 +1421,9 @@ print_crl (gnutls_string * str, gnutls_x509_crl_t crl, int notsigned) if (tim == -1) addf (str, "\t\tNo next update time.\n"); else if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); + addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); else if (strftime (s, max, "%a %b %d %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); + addf (str, "error: strftime (%ld)\n", (unsigned long) tim); else addf (str, _("\t\tNext at: %s\n"), s); } @@ -1582,9 +1582,9 @@ print_crl (gnutls_string * str, gnutls_x509_crl_t crl, int notsigned) adds (str, "\n"); if (gmtime_r (&tim, &t) == NULL) - addf (str, "error: gmtime_r (%d)\n", t); + addf (str, "error: gmtime_r (%ld)\n", (unsigned long) tim); else if (strftime (s, max, "%a %b %d %H:%M:%S UTC %Y", &t) == 0) - addf (str, "error: strftime (%d)\n", t); + addf (str, "error: strftime (%ld)\n", (unsigned long) tim); else addf (str, _("\t\tRevoked at: %s\n"), s); } diff --git a/lib/x509/privkey.c b/lib/x509/privkey.c index 53e2f28b7d..3e5c75f5f0 100644 --- a/lib/x509/privkey.c +++ b/lib/x509/privkey.c @@ -684,7 +684,7 @@ gnutls_x509_privkey_export (gnutls_x509_privkey_t key, gnutls_x509_crt_fmt_t format, void *output_data, size_t * output_data_size) { - char *msg; + const char *msg; int ret; if (key == NULL) diff --git a/libextra/fipsmd5.c b/libextra/fipsmd5.c index 114c396fd5..43939c82b1 100644 --- a/libextra/fipsmd5.c +++ b/libextra/fipsmd5.c @@ -22,6 +22,7 @@ #include <gnutls_int.h> #include <gnutls/crypto.h> +#include <gnutls/extra.h> #include <md5.h> #include <hmac.h> diff --git a/libextra/gnutls_extra.c b/libextra/gnutls_extra.c index 5b60e02186..5a81a59b01 100644 --- a/libextra/gnutls_extra.c +++ b/libextra/gnutls_extra.c @@ -34,6 +34,7 @@ # include <lzo1x.h> # endif #endif +#include <gnutls/extra.h> #ifdef USE_LZO #include <gnutls_compress.h> diff --git a/libextra/gnutls_openssl.c b/libextra/gnutls_openssl.c index cbf928c0e5..b079088f39 100644 --- a/libextra/gnutls_openssl.c +++ b/libextra/gnutls_openssl.c @@ -849,7 +849,7 @@ SSL_CIPHER_description (SSL_CIPHER * cipher, char *buf, int size) { if (local_alloc) free (tmpbuf); - return "Buffer too small"; + return (char*) "Buffer too small"; } return tmpbuf; diff --git a/src/Makefile.am b/src/Makefile.am index 0bc02b4ee0..19811bb072 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,14 +21,14 @@ EXTRA_DIST = README README.srptool SUBDIRS = cfg -INCS = \ +AM_CFLAGS = $(WARN_CFLAGS) +AM_CPPFLAGS = \ -I$(srcdir)/../gl \ -I$(builddir)/../gl \ -I$(builddir)/../lib/includes \ -I$(srcdir)/../lib/includes \ -I$(srcdir)/../libextra/includes \ -I$(srcdir)/cfg -AM_CPPFLAGS = $(WARN_CFLAGS) $(INCS) bin_PROGRAMS = gnutls-serv gnutls-cli psktool gnutls-cli-debug if ENABLE_PKI @@ -38,43 +38,65 @@ if ENABLE_SRP bin_PROGRAMS += srptool endif -gnutls_serv_SOURCES = serv.gaa serv-gaa.h serv-gaa.c list.h serv.c \ - common.h common.c certtool-common.h +noinst_LTLIBRARIES = + +gnutls_serv_SOURCES = list.h serv.c common.h common.c certtool-common.h gnutls_serv_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la \ - ../gl/libgnu.la + ../gl/libgnu.la libcmd-serv.la +noinst_LTLIBRARIES += libcmd-serv.la +libcmd_serv_la_CFLAGS = +libcmd_serv_la_SOURCES = serv.gaa serv-gaa.h serv-gaa.c if ENABLE_SRP -srptool_SOURCES = crypt.gaa crypt-gaa.h crypt-gaa.c crypt.c -srptool_LDADD = ../lib/libgnutls.la ../gl/libgnu.la ../lib/gl/liblgnu.la +srptool_SOURCES = crypt.c +srptool_LDADD = ../lib/libgnutls.la ../gl/libgnu.la ../lib/gl/liblgnu.la \ + libcmd-srp.la +noinst_LTLIBRARIES += libcmd-srp.la +libcmd_srp_la_CFLAGS = +libcmd_srp_la_SOURCES = crypt.gaa crypt-gaa.h crypt-gaa.c endif -psktool_SOURCES = psk.gaa psk-gaa.h psk-gaa.c psk.c -psktool_LDADD = ../lib/libgnutls.la ../gl/libgnu.la ../lib/gl/liblgnu.la +psktool_SOURCES = psk.c +psktool_LDADD = ../lib/libgnutls.la ../gl/libgnu.la ../lib/gl/liblgnu.la \ + libcmd-psk.la +noinst_LTLIBRARIES += libcmd-psk.la +libcmd_psk_la_CFLAGS = +libcmd_psk_la_SOURCES = psk.gaa psk-gaa.h psk-gaa.c -gnutls_cli_SOURCES = cli.gaa cli-gaa.h cli-gaa.c cli.c common.h \ - common.c +gnutls_cli_SOURCES = cli.c common.h common.c gnutls_cli_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la \ - ../gl/libgnu.la + ../gl/libgnu.la libcmd-cli.la +noinst_LTLIBRARIES += libcmd-cli.la +libcmd_cli_la_CFLAGS = +libcmd_cli_la_SOURCES = cli.gaa cli-gaa.h cli-gaa.c -gnutls_cli_debug_SOURCES = tls_test.gaa tls_test-gaa.h tls_test-gaa.c \ - tls_test.c tests.h tests.c common.h common.c -gnutls_cli_debug_LDADD = ../lib/libgnutls.la ../gl/libgnu.la +gnutls_cli_debug_SOURCES = tls_test.c tests.h tests.c common.h common.c +gnutls_cli_debug_LDADD = ../lib/libgnutls.la ../gl/libgnu.la \ + libcmd-cli-debug.la +noinst_LTLIBRARIES += libcmd-cli-debug.la +libcmd_cli_debug_la_CFLAGS = +libcmd_cli_debug_la_SOURCES = tls_test.gaa tls_test-gaa.h tls_test-gaa.c -certtool_SOURCES = certtool.gaa certtool-gaa.h certtool-cfg.h \ - certtool-gaa.c certtool.c prime.c certtool-cfg.c -certtool_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la \ - ../gl/libgnu.la ../lib/gl/liblgnu.la @LTLIBREADLINE@ +certtool_SOURCES = certtool.c prime.c +certtool_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la \ + ../gl/libgnu.la ../lib/gl/liblgnu.la @LTLIBREADLINE@ \ + libcmd-certtool.la if HAVE_LIBCFG certtool_LDADD += -lcfg+ else -noinst_LTLIBRARIES = libcfg.la -libcfg_la_CPPFLAGS = $(INCS) +noinst_LTLIBRARIES += libcfg.la +libcfg_la_CFLAGS = libcfg_la_SOURCES = cfg/cfg+.c cfg/cfgfile.c cfg/cmdline.c cfg/parse.c \ cfg/props.c cfg/shared.c cfg/platon/str/dynfgets.c \ cfg/platon/str/strctype.c cfg/platon/str/strdyn.c \ cfg/platon/str/strplus.c certtool_LDADD += libcfg.la endif +noinst_LTLIBRARIES += libcmd-certtool.la +libcmd_certtool_la_CFLAGS = +libcmd_certtool_la_SOURCES = certtool.gaa certtool-gaa.h \ + certtool-gaa.c certtool-cfg.h certtool-cfg.c +libcmd_certtool_la_LIBADD = ../gl/libgnu.la noinst_PROGRAMS = errcodes printlist errcodes_SOURCES = errcodes.c @@ -54,7 +54,7 @@ /* global stuff here */ int resume, starttls, insecure; -char *hostname = NULL; +const char *hostname = NULL; char *service; int record_max_size; int fingerprint; @@ -895,6 +895,8 @@ gaa_parser (int argc, char **argv) parse_comp (info.comp, info.ncomp, comp_priority); } +void cli_version (void); + void cli_version (void) { diff --git a/src/common.h b/src/common.h index 01e0fa5cc4..d209655986 100644 --- a/src/common.h +++ b/src/common.h @@ -14,6 +14,12 @@ # include <winbase.h> #endif +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# define __attribute__(Spec) /* empty */ +# endif +#endif + /* the number of elements in the priority structures. */ #define PRI_MAX 16 diff --git a/src/crypt.c b/src/crypt.c index c36230a1d0..8c53a01259 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -57,7 +57,6 @@ static int _verify_passwd_int (const char *username, const char *passwd, const gnutls_datum_t * g, const gnutls_datum_t * n); - static void print_num (const char *msg, const gnutls_datum_t * num) { @@ -419,9 +418,9 @@ main (int argc, char **argv) } if (info.passwd == NULL) - info.passwd = KPASSWD; + info.passwd = (char*) KPASSWD; if (info.passwd_conf == NULL) - info.passwd_conf = KPASSWD_CONF; + info.passwd_conf = (char*) KPASSWD_CONF; if (info.username == NULL) { @@ -710,6 +709,8 @@ read_conf_values (gnutls_datum_t * g, gnutls_datum_t * n, char *str) return index; } +extern void srptool_version(void); + void srptool_version (void) { diff --git a/src/prime.c b/src/prime.c index 213f31287e..9b07f95b9c 100644 --- a/src/prime.c +++ b/src/prime.c @@ -39,6 +39,8 @@ extern const int buffer_size; static int cparams = 0; +int generate_prime (int bits, int how); + /* If how is zero then the included parameters are used. */ int @@ -89,7 +89,7 @@ main (int argc, char **argv) } if (info.passwd == NULL) - info.passwd = KPASSWD; + info.passwd = (char*) KPASSWD; if (info.username == NULL) { @@ -300,6 +300,8 @@ write_key (const char *username, const char *key, int key_size, #endif /* ENABLE_PSK */ +void psktool_version (void); + void psktool_version (void) { diff --git a/src/serv.c b/src/serv.c index dbd76c225e..e650998654 100644 --- a/src/serv.c +++ b/src/serv.c @@ -742,6 +742,8 @@ unimplemented: *response_length = ((*response) ? strlen (*response) : 0); } +static void terminate (int sig) __attribute__ ((noreturn)); + static void terminate (int sig) { @@ -1433,6 +1435,8 @@ gaa_parser (int argc, char **argv) parse_comp (info.comp, info.ncomp, comp_priority); } +extern void serv_version(void); + void serv_version (void) { diff --git a/src/tls_test.c b/src/tls_test.c index 0f5d50151e..48c31e0114 100644 --- a/src/tls_test.c +++ b/src/tls_test.c @@ -40,7 +40,7 @@ /* global stuff here */ int resume; -char *hostname = NULL; +const char *hostname = NULL; int port; int record_max_size; int fingerprint; @@ -69,11 +69,11 @@ typedef test_code_t (*TEST_FUNC) (gnutls_session_t); typedef struct { - char *test_name; + const char *test_name; TEST_FUNC func; - char *suc_str; - char *fail_str; - char *unsure_str; + const char *suc_str; + const char *fail_str; + const char *unsure_str; } TLS_TEST; static const TLS_TEST tls_tests[] = { @@ -326,6 +326,8 @@ gaa_parser (int argc, char **argv) } +void tls_test_version (void); + void tls_test_version (void) { diff --git a/tests/Makefile.am b/tests/Makefile.am index c34a9dd830..da9e5d2277 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -28,8 +28,8 @@ endif EXTRA_DIST = libgcrypt.supp hostname-check.README +AM_CFLAGS = $(WARN_CFLAGS) AM_CPPFLAGS = \ - $(WARN_CFLAGS) \ -I$(top_srcdir)/gl \ -I$(top_builddir)/gl \ -I$(top_srcdir)/lib/includes \ diff --git a/tests/anonself.c b/tests/anonself.c index d2286bdb2a..2819becd54 100644 --- a/tests/anonself.c +++ b/tests/anonself.c @@ -37,6 +37,8 @@ #include <unistd.h> #include <gnutls/gnutls.h> +#include "tcp.c" + #include "utils.h" static void @@ -51,46 +53,7 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -void +static void client (void) { int ret, sd, ii; @@ -189,7 +152,7 @@ end: /* These are global */ gnutls_anon_server_credentials_t anoncred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -215,7 +178,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -235,7 +198,7 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -void +static void server_start (void) { /* Socket operations @@ -274,7 +237,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/crypto_rng.c b/tests/crypto_rng.c index e7fd425f14..5fd8557daf 100644 --- a/tests/crypto_rng.c +++ b/tests/crypto_rng.c @@ -32,28 +32,20 @@ #include <gnutls/crypto.h> #include "../lib/random.h" -void -mylogfn (int level, const char *ptr) -{ - printf ("Got Logs: "); - if (ptr) - printf ("%s", ptr); -} - -int +static int rng_init (void **ctx) { return 0; } -int +static int rng_rnd (void *ctx, int level, void *data, size_t datasize) { memset (data, 1, datasize); return 0; } -void +static void rng_deinit (void *ctx) { } diff --git a/tests/dhepskself.c b/tests/dhepskself.c index f0bf5d9d54..3d41f24c82 100644 --- a/tests/dhepskself.c +++ b/tests/dhepskself.c @@ -37,6 +37,8 @@ #include <unistd.h> #include <gnutls/gnutls.h> +#include "tcp.c" + #include "utils.h" /* A very basic TLS client, with PSK authentication. @@ -51,53 +53,14 @@ tls_log_func (int level, const char *str) fprintf (stderr, "|<%d>| %s", level, str); } -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -void +static void client (void) { int ret, sd, ii; gnutls_session_t session; char buffer[MAX_BUF + 1]; gnutls_psk_client_credentials_t pskcred; - const gnutls_datum_t key = { "DEADBEEF", 8 }; + const gnutls_datum_t key = { (char*) "DEADBEEF", 8 }; gnutls_global_init (); @@ -183,7 +146,7 @@ end: /* These are global */ gnutls_psk_server_credentials_t server_pskcred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -205,7 +168,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -238,7 +201,7 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -void +static void server_start (void) { success ("Launched, generating DH parameters...\n"); @@ -279,7 +242,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/dn.c b/tests/dn.c index 5528312b98..abae077665 100644 --- a/tests/dn.c +++ b/tests/dn.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007 Free Software Foundation + * Copyright (C) 2006, 2007, 2008 Free Software Foundation * Author: Simon Josefsson, Howard Chu * * This file is part of GNUTLS. @@ -59,7 +59,7 @@ static char pem[] = "bHarWgDg9CKVP1DggVkcD838s//kE1Vl2DReyfAtEQ1agSXLFncgxL+yOi1o3lcq\n" "+dmDgpDn168TY1Iug80uVKg7AfkLrA==\n" "-----END CERTIFICATE-----\n"; -void +static void print_dn (gnutls_x509_dn_t dn) { int i, j, ret = 0; diff --git a/tests/finished.c b/tests/finished.c index 4d82cd5403..5a5810ff4b 100644 --- a/tests/finished.c +++ b/tests/finished.c @@ -46,7 +46,7 @@ size_t to_server_len; char *to_client; size_t to_client_len; -ssize_t +static ssize_t client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { success ("client_pull len %d has %d\n", len, to_client_len); @@ -65,7 +65,7 @@ client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) return len; } -ssize_t +static ssize_t client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_server_len + len; @@ -88,7 +88,7 @@ client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) return len; } -ssize_t +static ssize_t server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { success ("server_pull len %d has %d\n", len, to_server_len); @@ -107,7 +107,7 @@ server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) return len; } -ssize_t +static ssize_t server_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_client_len + len; @@ -131,7 +131,7 @@ server_push (gnutls_transport_ptr_t tr, const void *data, size_t len) return len; } -void +static void client_finished_callback (gnutls_session_t session, const void *finished, size_t len) { @@ -139,7 +139,7 @@ client_finished_callback (gnutls_session_t session, hexprint (finished, len); } -void +static void server_finished_callback (gnutls_session_t session, const void *finished, size_t len) { @@ -155,7 +155,7 @@ doit (void) { /* Server stuff. */ gnutls_anon_server_credentials_t s_anoncred; - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; static gnutls_dh_params_t dh_params; gnutls_session_t server; int sret = GNUTLS_E_AGAIN; diff --git a/tests/gc.c b/tests/gc.c index 777a4a8992..70c6180525 100644 --- a/tests/gc.c +++ b/tests/gc.c @@ -32,12 +32,6 @@ #include "../lib/x509/pbkdf2-sha1.h" #include "../lib/debug.h" -int -is_secure_mem (const void *ign) -{ - return 0; -} - void doit (void) { diff --git a/tests/mini.c b/tests/mini.c index edda9f96b6..b64401db62 100644 --- a/tests/mini.c +++ b/tests/mini.c @@ -44,7 +44,7 @@ size_t to_server_len; char *to_client; size_t to_client_len; -ssize_t +static ssize_t client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { success ("client_pull len %d has %d\n", len, to_client_len); @@ -63,7 +63,7 @@ client_pull (gnutls_transport_ptr_t tr, void *data, size_t len) return len; } -ssize_t +static ssize_t client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_server_len + len; @@ -86,7 +86,7 @@ client_push (gnutls_transport_ptr_t tr, const void *data, size_t len) return len; } -ssize_t +static ssize_t server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) { success ("server_pull len %d has %d\n", len, to_server_len); @@ -105,7 +105,7 @@ server_pull (gnutls_transport_ptr_t tr, void *data, size_t len) return len; } -ssize_t +static ssize_t server_push (gnutls_transport_ptr_t tr, const void *data, size_t len) { size_t newlen = to_client_len + len; @@ -137,7 +137,7 @@ doit (void) { /* Server stuff. */ gnutls_anon_server_credentials_t s_anoncred; - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; static gnutls_dh_params_t dh_params; gnutls_session_t server; int sret = GNUTLS_E_AGAIN; diff --git a/tests/openpgpself.c b/tests/openpgpself.c index b399a111e8..fc802880cb 100644 --- a/tests/openpgpself.c +++ b/tests/openpgpself.c @@ -42,6 +42,7 @@ #include "ex-session-info.c" #include "ex-x509-info.c" +#include "tcp.c" pid_t child; @@ -57,45 +58,6 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - static unsigned char cert_txt[] = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" "Version: GnuPG v1.0.6 (GNU/Linux)\n" @@ -139,7 +101,7 @@ static unsigned char key_txt[] = "=4M0W\n" "-----END PGP PRIVATE KEY BLOCK-----\n"; const gnutls_datum_t key = { key_txt, sizeof (key_txt) }; -void +static void client (void) { int ret, sd, ii; @@ -249,7 +211,7 @@ end: /* These are global */ gnutls_certificate_credentials_t pgp_cred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -277,7 +239,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -372,7 +334,7 @@ static unsigned char server_key_txt[] = "=mZnW\n" "-----END PGP PRIVATE KEY BLOCK-----\n"; const gnutls_datum_t server_key = { server_key_txt, sizeof (server_key_txt) }; -void +static void server_start (void) { /* Socket operations @@ -411,7 +373,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/pkcs12_s2k.c b/tests/pkcs12_s2k.c index 03d1c66be9..f576137b35 100644 --- a/tests/pkcs12_s2k.c +++ b/tests/pkcs12_s2k.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Free Software Foundation + * Copyright (C) 2007, 2008 Free Software Foundation * * Author: Simon Josefsson * @@ -37,10 +37,10 @@ tls_log_func (int level, const char *str) fprintf (stderr, "|<%d>| %s", level, str); } -char *salt[3] = { "salt1", "ltsa22", "balt33" }; -char *pw[3] = { "secret1", "verysecret2", "veryverysecret3" }; +static const char *salt[3] = { "salt1", "ltsa22", "balt33" }; +static const char *pw[3] = { "secret1", "verysecret2", "veryverysecret3" }; -char *values[] = { +static const char *values[] = { /* 1.0 */ "85a3c676a66f0960f4807144a28c8d61a0001b81846f301a1ac164289879972f", /* 1.2 */ diff --git a/tests/pskself.c b/tests/pskself.c index 107b4e4324..3fb3c5875a 100644 --- a/tests/pskself.c +++ b/tests/pskself.c @@ -37,6 +37,8 @@ #include <unistd.h> #include <gnutls/gnutls.h> +#include "tcp.c" + #include "utils.h" /* A very basic TLS client, with PSK authentication. @@ -45,46 +47,7 @@ #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -void +static void client (void) { int ret, sd, ii; @@ -93,7 +56,7 @@ client (void) gnutls_psk_client_credentials_t pskcred; /* Need to enable anonymous KX specifically. */ const int kx_prio[] = { GNUTLS_KX_PSK, 0 }; - const gnutls_datum_t key = { "DEADBEEF", 8 }; + const gnutls_datum_t key = { (char*) "DEADBEEF", 8 }; gnutls_global_init (); @@ -181,7 +144,7 @@ end: /* These are global */ gnutls_psk_server_credentials_t server_pskcred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -223,7 +186,7 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -void +static void server_start (void) { success ("Launched...\n"); @@ -264,7 +227,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/resume.c b/tests/resume.c index 2dd656fee1..b70bac444b 100644 --- a/tests/resume.c +++ b/tests/resume.c @@ -37,6 +37,8 @@ #include <unistd.h> #include <gnutls/gnutls.h> +#include "tcp.c" + #include "utils.h" static void wrap_db_init (void); @@ -53,46 +55,7 @@ static int wrap_db_delete (void *dbf, gnutls_datum_t key); #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -void +static void client (void) { int ret, sd, ii; @@ -223,7 +186,7 @@ client (void) /* These are global */ gnutls_anon_server_credentials_t anoncred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -257,7 +220,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -277,7 +240,7 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -void +static void global_start (void) { /* Socket operations @@ -316,7 +279,7 @@ global_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void global_stop (void) { success ("global stop\n"); @@ -328,7 +291,7 @@ global_stop (void) gnutls_global_deinit (); } -void +static void server (void) { size_t t; diff --git a/tests/set_pkcs12_cred.c b/tests/set_pkcs12_cred.c index c0349a24c3..ebdf8b111e 100644 --- a/tests/set_pkcs12_cred.c +++ b/tests/set_pkcs12_cred.c @@ -32,7 +32,7 @@ void doit (void) { gnutls_certificate_credentials_t x509cred; - char *file, *password; + const char *file, *password; int ret; ret = gnutls_global_init (); diff --git a/tests/tlsia.c b/tests/tlsia.c index 80e82be311..3b03b251bc 100644 --- a/tests/tlsia.c +++ b/tests/tlsia.c @@ -40,6 +40,8 @@ #include "utils.h" +#include "tcp.c" + #include <readline.h> /* A very basic TLS client, with anonymous authentication. @@ -48,51 +50,12 @@ #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - -int +static int client_avp (gnutls_session_t session, void *ptr, const char *last, size_t lastlen, char **new, size_t * newlen) { static int iter = 0; - char *p; + const char *p; if (last) printf ("client: received %d bytes AVP: `%.*s'\n", @@ -137,7 +100,7 @@ client_avp (gnutls_session_t session, void *ptr, return 0; } -void +static void client (void) { int ret, sd, ii; @@ -273,7 +236,7 @@ end: gnutls_anon_server_credentials_t anoncred; gnutls_ia_server_credentials_t iacred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -299,7 +262,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -319,12 +282,12 @@ gnutls_session_t session; char buffer[MAX_BUF + 1]; int optval = 1; -int +static int server_avp (gnutls_session_t session, void *ptr, const char *last, size_t lastlen, char **new, size_t * newlen) { static int iter = 0; - char *p; + const char *p; if (last) printf ("server: received %d bytes AVP: `%.*s'\n", @@ -397,7 +360,7 @@ server_avp (gnutls_session_t session, void *ptr, return 0; } -void +static void server_start (void) { /* Socket operations @@ -436,7 +399,7 @@ server_start (void) success ("server: ready. Listening to port '%d'\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/utils.c b/tests/utils.c index 3630318bb4..441a9d0511 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation * * Author: Simon Josefsson * @@ -33,7 +33,7 @@ int debug = 0; int error_count = 0; int break_on_error = 0; -char *pkcs3 = +const char *pkcs3 = "-----BEGIN DH PARAMETERS-----\n" "MIGGAoGAtkxw2jlsVCsrfLqxrN+IrF/3W8vVFvDzYbLmxi2GQv9s/PQGWP1d9i22\n" "P2DprfcJknWt7KhCI1SaYseOQIIIAYP78CfyIpGScW/vS8khrw0rlQiyeCvQgF3O\n" diff --git a/tests/utils.h b/tests/utils.h index 88d100f73d..cb3c57b6ee 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2007 Free Software Foundation + * Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation * * Author: Simon Josefsson * @@ -27,14 +27,22 @@ # include <stdarg.h> # include <gnutls/gnutls.h> +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# define __attribute__(Spec) /* empty */ +# endif +#endif + extern int debug; extern int error_count; extern int break_on_error; -extern char *pkcs3; +extern const char *pkcs3; -extern void fail (const char *format, ...); -extern void success (const char *format, ...); +extern void fail (const char *format, ...) + __attribute__ ((format (printf, 1, 2))); +extern void success (const char *format, ...) + __attribute__ ((format (printf, 1, 2))); extern void escapeprint (const char *str, size_t len); extern void hexprint (const char *str, size_t len); diff --git a/tests/x509dn.c b/tests/x509dn.c index 9434ee9979..27ad6f1cd4 100644 --- a/tests/x509dn.c +++ b/tests/x509dn.c @@ -41,6 +41,7 @@ #include "ex-session-info.c" #include "ex-x509-info.c" +#include "tcp.c" pid_t child; @@ -56,45 +57,6 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - static unsigned char ca_pem[] = "-----BEGIN CERTIFICATE-----\n" "MIIB5zCCAVKgAwIBAgIERiYdJzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n" @@ -210,7 +172,7 @@ cert_callback (gnutls_session session, } -void +static void client (void) { int ret, sd, ii; @@ -315,7 +277,7 @@ end: /* These are global */ gnutls_certificate_credentials_t x509_cred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -343,7 +305,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -405,7 +367,7 @@ const gnutls_datum_t server_key = { server_key_pem, sizeof (server_key_pem) }; -void +static void server_start (void) { /* Socket operations @@ -444,7 +406,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/x509self.c b/tests/x509self.c index 1d6c26e045..fd95190156 100644 --- a/tests/x509self.c +++ b/tests/x509self.c @@ -41,6 +41,7 @@ #include "ex-session-info.c" #include "ex-x509-info.c" +#include "tcp.c" pid_t child; @@ -56,45 +57,6 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - static unsigned char ca_pem[] = "-----BEGIN CERTIFICATE-----\n" "MIIB5zCCAVKgAwIBAgIERiYdJzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n" @@ -144,7 +106,7 @@ static unsigned char key_pem[] = "-----END RSA PRIVATE KEY-----\n"; const gnutls_datum_t key = { key_pem, sizeof (key_pem) }; -void +static void client (void) { int ret, sd, ii; @@ -249,7 +211,7 @@ end: /* These are global */ gnutls_certificate_credentials_t x509_cred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -277,7 +239,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -339,7 +301,7 @@ const gnutls_datum_t server_key = { server_key_pem, sizeof (server_key_pem) }; -void +static void server_start (void) { /* Socket operations @@ -378,7 +340,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program diff --git a/tests/x509signself.c b/tests/x509signself.c index 7920cc6f00..7b1586a149 100644 --- a/tests/x509signself.c +++ b/tests/x509signself.c @@ -40,7 +40,7 @@ #include "ex-session-info.c" #include "ex-x509-info.c" -extern int print_info (gnutls_session_t session); +#include "tcp.c" #include "utils.h" @@ -58,45 +58,6 @@ tls_log_func (int level, const char *str) #define MAX_BUF 1024 #define MSG "Hello TLS" -/* Connects to the peer and returns a socket - * descriptor. - */ -int -tcp_connect (void) -{ - const char *PORT = "5556"; - const char *SERVER = "127.0.0.1"; - int err, sd; - struct sockaddr_in sa; - - /* connects to server - */ - sd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&sa, '\0', sizeof (sa)); - sa.sin_family = AF_INET; - sa.sin_port = htons (atoi (PORT)); - inet_pton (AF_INET, SERVER, &sa.sin_addr); - - err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); - if (err < 0) - { - fprintf (stderr, "Connect error\n"); - exit (1); - } - - return sd; -} - -/* closes the given socket descriptor. - */ -void -tcp_close (int sd) -{ - shutdown (sd, SHUT_RDWR); /* no more receptions */ - close (sd); -} - static char ca_pem[] = "-----BEGIN CERTIFICATE-----\n" "MIIB5zCCAVKgAwIBAgIERiYdJzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n" @@ -128,7 +89,7 @@ static char cert_pem[] = "dc8Siq5JojruiMizAf0pA7in\n" "-----END CERTIFICATE-----\n"; const gnutls_datum_t cert = { cert_pem, sizeof (cert_pem) }; -int +static int sign_func (gnutls_session_t session, void *userdata, gnutls_certificate_type_t cert_type, @@ -174,7 +135,7 @@ done: return ret; } -void +static void client (void) { int ret, sd, ii; @@ -282,7 +243,7 @@ end: /* These are global */ gnutls_certificate_credentials_t x509_cred; -gnutls_session_t +static gnutls_session_t initialize_tls_session (void) { gnutls_session_t session; @@ -310,7 +271,7 @@ static gnutls_dh_params_t dh_params; static int generate_dh_params (void) { - const gnutls_datum_t p3 = { pkcs3, strlen (pkcs3) }; + const gnutls_datum_t p3 = { (char*) pkcs3, strlen (pkcs3) }; /* Generate Diffie Hellman parameters - for use with DHE * kx algorithms. These should be discarded and regenerated * once a day, once a week or once a month. Depending on the @@ -371,7 +332,7 @@ const gnutls_datum_t server_key = { server_key_pem, sizeof (server_key_pem) }; -void +static void server_start (void) { /* Socket operations @@ -410,7 +371,7 @@ server_start (void) success ("server: ready. Listening to port '%d'.\n", PORT); } -void +static void server (void) { /* this must be called once in the program |