From 3b205dfa87e946f28b255ac6b0dd49d08583cf77 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 6 Dec 2001 17:08:04 +0000 Subject: GNUTLS_LIST is now int* --- lib/defines.h | 12 ---- lib/gnutls.h.in | 2 +- lib/gnutls_algorithms.c | 6 +- lib/gnutls_int.h | 2 +- lib/gnutls_priority.c | 142 +++++++++++++++++------------------------------- lib/gnutls_record.c | 3 +- 6 files changed, 57 insertions(+), 110 deletions(-) (limited to 'lib') diff --git a/lib/defines.h b/lib/defines.h index 6cb52adff7..6d71591ee7 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -39,10 +39,6 @@ typedef int ssize_t; #endif -#ifdef HAVE_STDARG_H -# include -#endif - #ifdef HAVE_STRINGS_H # include #endif @@ -122,12 +118,4 @@ # endif #endif -#ifdef USE_VA_COPY -# ifndef HAVE_VA_COPY -# define VA_COPY __va_copy -# else -# define VA_COPY va_copy -# endif -#endif - #endif /* defines_h */ diff --git a/lib/gnutls.h.in b/lib/gnutls.h.in index 9bfc3d7bdc..0b62318652 100644 --- a/lib/gnutls.h.in +++ b/lib/gnutls.h.in @@ -62,7 +62,7 @@ typedef enum GNUTLS_Version { GNUTLS_SSL3=1, GNUTLS_TLS1 } GNUTLS_Version; */ #define GNUTLS_SOCKET_PTR int -#define GNUTLS_LIST ... +typedef const int* GNUTLS_LIST; struct GNUTLS_STATE_INT; typedef struct GNUTLS_STATE_INT* GNUTLS_STATE; diff --git a/lib/gnutls_algorithms.c b/lib/gnutls_algorithms.c index 72f409e5b3..22ed428866 100644 --- a/lib/gnutls_algorithms.c +++ b/lib/gnutls_algorithms.c @@ -438,7 +438,7 @@ const char *gnutls_mac_get_name(MACAlgorithm algorithm) /* avoid prefix */ GNUTLS_HASH_ALG_LOOP(ret = - p->name + sizeof("GNUTLS_") - 1); + p->name + sizeof("GNUTLS_MAC_") - 1); return ret; } @@ -495,7 +495,7 @@ const char *gnutls_compression_get_name(CompressionMethod algorithm) /* avoid prefix */ GNUTLS_COMPRESSION_ALG_LOOP(ret = - p->name + sizeof("GNUTLS_") - + p->name + sizeof("GNUTLS_COMP_") - 1); return ret; @@ -613,7 +613,7 @@ const char *gnutls_cipher_get_name(BulkCipherAlgorithm algorithm) char *ret = NULL; /* avoid prefix */ - GNUTLS_ALG_LOOP(ret = p->name + sizeof("GNUTLS_") - 1); + GNUTLS_ALG_LOOP(ret = p->name + sizeof("GNUTLS_CIPHER_") - 1); return ret; } diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index 85eee4870d..06c702f8e1 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -40,7 +40,7 @@ */ #define GNUTLS_SOCKET_PTR int -#define GNUTLS_LIST ... +typedef const int* GNUTLS_LIST; #define MIN_BITS 1023 diff --git a/lib/gnutls_priority.c b/lib/gnutls_priority.c index e2d556a9cd..21c83f99dd 100644 --- a/lib/gnutls_priority.c +++ b/lib/gnutls_priority.c @@ -27,7 +27,7 @@ /** * gnutls_cipher_set_priority - Sets the priority on the ciphers supported by gnutls. * @state: is a &GNUTLS_STATE structure. - * @GNUTLS_LIST: is a 0 terminated list of BulkCipherAlgorithm elements. + * @list: is a 0 terminated list of BulkCipherAlgorithm elements. * * Sets the priority on the ciphers supported by gnutls. * Priority is higher for ciphers specified before others. @@ -36,22 +36,13 @@ * not use the algorithm's priority except for disabling * algorithms that were not specified. **/ -int gnutls_cipher_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { - - va_list ap; - int i,num=0; - va_list _ap; - - va_start( ap, state); +int gnutls_cipher_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) { +GNUTLS_LIST _list = list; +int num=0, i; -#ifdef USE_VA_COPY - VA_COPY( _ap, ap); -#else - _ap = ap; -#endif - - while( va_arg(ap, BulkCipherAlgorithm) != 0) { + while( *_list != 0) { num++; + ++_list; } if (state->gnutls_internals.BulkCipherAlgorithmPriority.algorithm_priority!=NULL) @@ -64,18 +55,16 @@ int gnutls_cipher_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { state->gnutls_internals.BulkCipherAlgorithmPriority.algorithms = num; for (i=0;ignutls_internals.BulkCipherAlgorithmPriority.algorithm_priority[i] = va_arg(_ap, BulkCipherAlgorithm); + state->gnutls_internals.BulkCipherAlgorithmPriority.algorithm_priority[i] = list[i]; } - va_end(ap); - return 0; } /** * gnutls_kx_set_priority - Sets the priority on the key exchange algorithms supported by gnutls. * @state: is a &GNUTLS_STATE structure. - * @GNUTLS_LIST: is a 0 terminated list of KXAlgorithm elements. + * @list: is a 0 terminated list of KXAlgorithm elements. * * Sets the priority on the key exchange algorithms supported by gnutls. * Priority is higher for algorithms specified before others. @@ -84,23 +73,15 @@ int gnutls_cipher_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { * not use the algorithm's priority except for disabling * algorithms that were not specified. **/ -int gnutls_kx_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { - - va_list ap; - va_list _ap; - int i,num=0; - - va_start( ap, state); +int gnutls_kx_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) { +GNUTLS_LIST _list = list; +int num=0, i; -#ifdef USE_VA_COPY - VA_COPY( _ap, ap); -#else - _ap = ap; -#endif - - while( va_arg(ap, KXAlgorithm) != 0) { + while( *_list != 0) { num++; - } + ++_list; + } + if (state->gnutls_internals.KXAlgorithmPriority.algorithm_priority!=NULL) gnutls_free(state->gnutls_internals.KXAlgorithmPriority.algorithm_priority); @@ -110,17 +91,16 @@ int gnutls_kx_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { state->gnutls_internals.KXAlgorithmPriority.algorithms = num; for (i=0;ignutls_internals.KXAlgorithmPriority.algorithm_priority[i] = va_arg( _ap, KXAlgorithm); + state->gnutls_internals.KXAlgorithmPriority.algorithm_priority[i] = list[i]; } - va_end(ap); return 0; } /** * gnutls_mac_set_priority - Sets the priority on the mac algorithms supported by gnutls. * @state: is a &GNUTLS_STATE structure. - * @GNUTLS_LIST: is a 0 terminated list of MACAlgorithm elements. + * @list: is a 0 terminated list of MACAlgorithm elements. * * Sets the priority on the mac algorithms supported by gnutls. * Priority is higher for algorithms specified before others. @@ -129,23 +109,15 @@ int gnutls_kx_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { * not use the algorithm's priority except for disabling * algorithms that were not specified. **/ -int gnutls_mac_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { - - va_list ap; - int i, num=0; - va_list _ap; - - va_start( ap, state); +int gnutls_mac_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) { +GNUTLS_LIST _list = list; +int num=0, i; -#ifdef USE_VA_COPY - VA_COPY( _ap, ap); -#else - _ap = ap; -#endif - - while( va_arg(ap, MACAlgorithm) != 0) { + while( *_list != 0) { num++; - } + ++_list; + } + if (state->gnutls_internals.MACAlgorithmPriority.algorithm_priority!=NULL) gnutls_free(state->gnutls_internals.MACAlgorithmPriority.algorithm_priority); @@ -155,17 +127,16 @@ int gnutls_mac_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { state->gnutls_internals.MACAlgorithmPriority.algorithms = num; for (i=0;ignutls_internals.MACAlgorithmPriority.algorithm_priority[i] = va_arg(_ap, MACAlgorithm); + state->gnutls_internals.MACAlgorithmPriority.algorithm_priority[i] = list[i]; } - va_end(ap); return 0; } /** * gnutls_compression_set_priority - Sets the priority on the compression algorithms supported by gnutls. * @state: is a &GNUTLS_STATE structure. - * @GNUTLS_LIST: is a 0 terminated list of CompressionMethod elements. + * @list: is a 0 terminated list of CompressionMethod elements. * * Sets the priority on the compression algorithms supported by gnutls. * Priority is higher for algorithms specified before others. @@ -174,23 +145,14 @@ int gnutls_mac_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { * not use the algorithm's priority except for disabling * algorithms that were not specified. **/ -int gnutls_compression_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { - - va_list ap; - int i,num=0; - va_list _ap; - - va_start( ap, state); - -#ifdef USE_VA_COPY - VA_COPY( _ap, ap); -#else - _ap = ap; -#endif +int gnutls_compression_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) { +GNUTLS_LIST _list = list; +int num=0, i; - while( va_arg( ap, CompressionMethod) != 0) { + while( *_list != 0) { num++; - } + ++_list; + } if (state->gnutls_internals.CompressionMethodPriority.algorithm_priority!=NULL) gnutls_free(state->gnutls_internals.CompressionMethodPriority.algorithm_priority); @@ -200,16 +162,15 @@ int gnutls_compression_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { state->gnutls_internals.CompressionMethodPriority.algorithms = num; for (i=0;ignutls_internals.CompressionMethodPriority.algorithm_priority[i] = va_arg( _ap, CompressionMethod); + state->gnutls_internals.CompressionMethodPriority.algorithm_priority[i] = list[i]; } - va_end(ap); return 0; } /** * gnutls_protocol_set_priority - Sets the priority on the protocol versions supported by gnutls. * @state: is a &GNUTLS_STATE structure. - * @GNUTLS_LIST: is a 0 terminated list of GNUTLS_Version elements. + * @list: is a 0 terminated list of GNUTLS_Version elements. * * Sets the priority on the protocol versions supported by gnutls. * Priority is higher for protocols specified before others. @@ -218,23 +179,16 @@ int gnutls_compression_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { * not use the protocols's priority except for disabling * protocols that were not specified. **/ -int gnutls_protocol_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { - - va_list ap; - int i,num=0; - va_list _ap; - - va_start( ap, state); - -#ifdef USE_VA_COPY - VA_COPY( _ap, ap); -#else - _ap = ap; -#endif +int gnutls_protocol_set_priority( GNUTLS_STATE state, GNUTLS_LIST list) { +GNUTLS_LIST _list = list; +int num=0, i; +GNUTLS_Version ver; - while( va_arg( ap, int) != 0) { + while( *_list != 0) { num++; - } + ++_list; + } + if (state->gnutls_internals.ProtocolPriority.algorithm_priority!=NULL) gnutls_free(state->gnutls_internals.ProtocolPriority.algorithm_priority); @@ -248,12 +202,16 @@ int gnutls_protocol_set_priority( GNUTLS_STATE state, GNUTLS_LIST) { state->gnutls_internals.ProtocolPriority.algorithms = num; for (i=0;ignutls_internals.ProtocolPriority.algorithm_priority[i] = va_arg( _ap, GNUTLS_Version); + state->gnutls_internals.ProtocolPriority.algorithm_priority[i] = list[i]; } - va_end(ap); - /* set the current version to the lowest + /* set the current version to the first chosen by the peer. */ - _gnutls_set_current_version( state, state->gnutls_internals.ProtocolPriority.algorithm_priority[num-1]); + ver = _gnutls_version_lowest( state); + if (ver < 0) { + gnutls_assert(); + return GNUTLS_E_UNKNOWN_ERROR; + } + _gnutls_set_current_version( state, ver); return 0; } diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c index 3bfddc0328..82fbcb679e 100644 --- a/lib/gnutls_record.c +++ b/lib/gnutls_record.c @@ -98,6 +98,7 @@ void gnutls_transport_set_ptr(GNUTLS_STATE state, GNUTLS_SOCKET_PTR ptr) { **/ int gnutls_init(GNUTLS_STATE * state, ConnectionEnd con_end) { +int default_protocol_list[] = { GNUTLS_TLS1, 0 }; *state = gnutls_calloc(1, sizeof(struct GNUTLS_STATE_INT)); if (*state==NULL) return GNUTLS_E_MEMORY_ERROR; @@ -116,7 +117,7 @@ int gnutls_init(GNUTLS_STATE * state, ConnectionEnd con_end) (*state)->gnutls_internals.resumable = RESUME_TRUE; - gnutls_protocol_set_priority( *state, GNUTLS_TLS1, 0); /* default */ + gnutls_protocol_set_priority( *state, default_protocol_list); /* default */ (*state)->gnutls_key = gnutls_calloc(1, sizeof(struct GNUTLS_KEY_INT)); if ( (*state)->gnutls_key == NULL) { -- cgit v1.2.1