libsoup r1080 - in trunk: . libsoup tests



Author: danw
Date: Sat Feb  9 05:08:29 2008
New Revision: 1080
URL: http://svn.gnome.org/viewvc/libsoup?rev=1080&view=rev

Log:
	* libsoup/soup-auth-manager-ntlm.c: mark the DES magic number
	arrays const

	* libsoup/soup-date.c (months, days): add an extra "const" to each
	of these declarations, as one "const" is apparently not enough.
	(soup_date_to_time_t): remove redundant copy of days_before array.

	* libsoup/soup-dns.c (soup_dns_init): use g_once_init_enter/leave

	* libsoup/soup-gnutls.c (soup_ssl_supported)
	(soup_gnutls_channel_funcs): Mark these const
	(soup_gnutls_init, init_dh_params): Use g_once_init_enter/leave

	* libsoup/soup-status.c (reason_phrases): mark this const

	* tests/ssl-test.c: Remove the workaround for soup_gnutls_init()
	not being thread-safe, since it is now.


Modified:
   trunk/ChangeLog
   trunk/libsoup/soup-auth-manager-ntlm.c
   trunk/libsoup/soup-date.c
   trunk/libsoup/soup-dns.c
   trunk/libsoup/soup-gnutls.c
   trunk/libsoup/soup-misc.h
   trunk/libsoup/soup-nossl.c
   trunk/libsoup/soup-status.c
   trunk/tests/ssl-test.c

Modified: trunk/libsoup/soup-auth-manager-ntlm.c
==============================================================================
--- trunk/libsoup/soup-auth-manager-ntlm.c	(original)
+++ trunk/libsoup/soup-auth-manager-ntlm.c	Sat Feb  9 05:08:29 2008
@@ -685,7 +685,7 @@
 
 
 /* Public domain DES implementation from Phil Karn */
-static guint32 Spbox[8][64] = {
+static const guint32 Spbox[8][64] = {
 	{ 0x01010400,0x00000000,0x00010000,0x01010404,
 	  0x01010004,0x00010404,0x00000004,0x00010000,
 	  0x00000400,0x01010400,0x01010404,0x00000400,
@@ -924,7 +924,7 @@
 /* Key schedule-related tables from FIPS-46 */
 
 /* permuted choice table (key) */
-static unsigned char pc1[] = {
+static const unsigned char pc1[] = {
 	57, 49, 41, 33, 25, 17,  9,
 	 1, 58, 50, 42, 34, 26, 18,
 	10,  2, 59, 51, 43, 35, 27,
@@ -937,12 +937,12 @@
 };
 
 /* number left rotations of pc1 */
-static unsigned char totrot[] = {
+static const unsigned char totrot[] = {
 	1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28
 };
 
 /* permuted choice key (table) */
-static unsigned char pc2[] = {
+static const unsigned char pc2[] = {
 	14, 17, 11, 24,  1,  5,
 	 3, 28, 15,  6, 21, 10,
 	23, 19, 12,  4, 26,  8,
@@ -957,7 +957,7 @@
 
 
 /* bit 0 is left-most in byte */
-static int bytebit[] = {
+static const int bytebit[] = {
 	0200,0100,040,020,010,04,02,01
 };
 

Modified: trunk/libsoup/soup-date.c
==============================================================================
--- trunk/libsoup/soup-date.c	(original)
+++ trunk/libsoup/soup-date.c	Sat Feb  9 05:08:29 2008
@@ -37,13 +37,13 @@
  **/
 
 /* Do not internationalize */
-static const char *months[] = {
+static const char *const months[] = {
 	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
 	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
 /* Do not internationalize */
-static const char *days[] = {
+static const char *const days[] = {
 	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
 };
 
@@ -513,9 +513,6 @@
 soup_date_to_time_t (SoupDate *date)
 {
 	time_t tt;
-	static const int days_before[] = {
-		0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
-	};
 
 	/* FIXME: offset, etc */
 
@@ -533,7 +530,7 @@
 
 	tt = (date->year - 1970) * 365;
 	tt += (date->year - 1968) / 4;
-	tt += days_before[date->month - 1] + date->day - 1;
+	tt += days_before[date->month] + date->day - 1;
 	if (date->year % 4 == 0 && date->month <= 2)
 		tt--;
 	tt = ((((tt * 24) + date->hour) * 60) + date->minute) * 60 + date->second;

Modified: trunk/libsoup/soup-dns.c
==============================================================================
--- trunk/libsoup/soup-dns.c	(original)
+++ trunk/libsoup/soup-dns.c	Sat Feb  9 05:08:29 2008
@@ -155,13 +155,17 @@
 void
 soup_dns_init (void)
 {
-	if (soup_dns_cache == NULL) {
+	static volatile gsize inited_dns = 0;
+
+	if (g_once_init_enter (&inited_dns)) {
 		soup_dns_cache = g_hash_table_new (soup_str_case_hash, soup_str_case_equal);
 		soup_dns_lock = g_mutex_new ();
 		soup_dns_cond = g_cond_new ();
 #if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GETNAMEINFO)
 		soup_gethost_lock = g_mutex_new ();
 #endif
+
+		g_once_init_leave (&inited_dns, TRUE);
 	}
 }
 

Modified: trunk/libsoup/soup-gnutls.c
==============================================================================
--- trunk/libsoup/soup-gnutls.c	(original)
+++ trunk/libsoup/soup-gnutls.c	Sat Feb  9 05:08:29 2008
@@ -31,7 +31,7 @@
  *
  * Can be used to test if libsoup was compiled with ssl support.
  **/
-gboolean soup_ssl_supported = TRUE;
+const gboolean soup_ssl_supported = TRUE;
 
 #define DH_BITS 1024
 
@@ -335,7 +335,7 @@
 	return chan->real_sock->funcs->io_get_flags (channel);
 }
 
-GIOFuncs soup_gnutls_channel_funcs = {
+const GIOFuncs soup_gnutls_channel_funcs = {
 	soup_gnutls_read,
 	soup_gnutls_write,
 	soup_gnutls_seek,
@@ -351,21 +351,20 @@
 static gboolean
 init_dh_params (void)
 {
-	if (gnutls_dh_params_init (&dh_params) != 0)
-		goto THROW_CREATE_ERROR;
-
-	if (gnutls_dh_params_generate2 (dh_params, DH_BITS) != 0)
-		goto THROW_CREATE_ERROR;
+	static volatile gsize inited_dh_params = 0;
 
-	return TRUE;
-
-THROW_CREATE_ERROR:
-	if (dh_params) {
-		gnutls_dh_params_deinit (dh_params);
-		dh_params = NULL;
+	if (g_once_init_enter (&inited_dh_params)) {
+		if (gnutls_dh_params_init (&dh_params) != 0 ||
+		    gnutls_dh_params_generate2 (dh_params, DH_BITS) != 0) {
+			if (dh_params) {
+				gnutls_dh_params_deinit (dh_params);
+				dh_params = NULL;
+			}
+		}
+		g_once_init_leave (&inited_dh_params, TRUE);
 	}
 
-	return FALSE;
+	return dh_params != NULL;
 }
 
 /**
@@ -427,7 +426,7 @@
 	g_io_channel_ref (sock);
 
 	gchan = (GIOChannel *) chan;
-	gchan->funcs = &soup_gnutls_channel_funcs;
+	gchan->funcs = (GIOFuncs *)&soup_gnutls_channel_funcs;
 	g_io_channel_init (gchan);
 	gchan->is_readable = gchan->is_writeable = TRUE;
 	gchan->use_buffer = FALSE;
@@ -440,8 +439,6 @@
 	return NULL;
 }
 
-static gboolean soup_gnutls_inited = FALSE;
-
 #ifdef GCRY_THREAD_OPTION_PTHREAD_IMPL
 GCRY_THREAD_OPTION_PTHREAD_IMPL;
 #endif
@@ -449,11 +446,15 @@
 static void
 soup_gnutls_init (void)
 {
+	static volatile gsize inited_gnutls = 0;
+
+	if (g_once_init_enter (&inited_gnutls)) {
 #ifdef GCRY_THREAD_OPTION_PTHREAD_IMPL
-	gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+		gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
 #endif
-	gnutls_global_init ();
-	soup_gnutls_inited = TRUE;
+		gnutls_global_init ();
+		g_once_init_leave (&inited_gnutls, TRUE);
+	}
 }
 
 /**
@@ -477,8 +478,7 @@
 	SoupSSLCredentials *creds;
 	int status;
 
-	if (!soup_gnutls_inited)
-		soup_gnutls_init ();
+	soup_gnutls_init ();
 
 	creds = g_slice_new0 (SoupSSLCredentials);
 	gnutls_certificate_allocate_credentials (&creds->creds);
@@ -533,12 +533,9 @@
 {
 	SoupSSLCredentials *creds;
 
-	if (!soup_gnutls_inited)
-		soup_gnutls_init ();
-	if (!dh_params) {
-		if (!init_dh_params ())
-			return NULL;
-	}
+	soup_gnutls_init ();
+	if (!init_dh_params ())
+		return NULL;
 
 	creds = g_slice_new0 (SoupSSLCredentials);
 	gnutls_certificate_allocate_credentials (&creds->creds);

Modified: trunk/libsoup/soup-misc.h
==============================================================================
--- trunk/libsoup/soup-misc.h	(original)
+++ trunk/libsoup/soup-misc.h	Sat Feb  9 05:08:29 2008
@@ -35,7 +35,7 @@
 gboolean           soup_str_case_equal       (gconstpointer v1,
 					      gconstpointer v2);
 
-extern gboolean soup_ssl_supported;
+extern const gboolean soup_ssl_supported;
 
 #define SOUP_SSL_ERROR soup_ssl_error_quark()
 

Modified: trunk/libsoup/soup-nossl.c
==============================================================================
--- trunk/libsoup/soup-nossl.c	(original)
+++ trunk/libsoup/soup-nossl.c	Sat Feb  9 05:08:29 2008
@@ -14,7 +14,7 @@
 
 #ifndef HAVE_SSL
 
-gboolean soup_ssl_supported = FALSE;
+const gboolean soup_ssl_supported = FALSE;
 
 GIOChannel *
 soup_ssl_wrap_iochannel (GIOChannel *sock, SoupSSLType type,

Modified: trunk/libsoup/soup-status.c
==============================================================================
--- trunk/libsoup/soup-status.c	(original)
+++ trunk/libsoup/soup-status.c	Sat Feb  9 05:08:29 2008
@@ -148,7 +148,7 @@
  * network and internal errors.
  **/
 
-static struct {
+static const struct {
 	guint code;
 	const char *phrase;
 } reason_phrases [] = {

Modified: trunk/tests/ssl-test.c
==============================================================================
--- trunk/tests/ssl-test.c	(original)
+++ trunk/tests/ssl-test.c	Sat Feb  9 05:08:29 2008
@@ -277,7 +277,11 @@
 	getsockname (listener, (struct sockaddr *)&sin, (void *)&sin_len);
 	port = ntohs (sin.sin_port);
 
-	/* Create the client */
+	/* Now spawn server thread */
+	server = g_thread_create (server_thread, GINT_TO_POINTER (listener),
+				  TRUE, NULL);
+
+	/* And create the client */
 	addr = soup_address_new ("127.0.0.1", port);
 	creds = soup_ssl_get_client_credentials (NULL);
 	sock = soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS, addr,
@@ -293,10 +297,6 @@
 
 	soup_socket_start_ssl (sock, NULL);
 
-	/* Now spawn server thread */
-	server = g_thread_create (server_thread, GINT_TO_POINTER (listener),
-				  TRUE, NULL);
-
 	/* Synchronous client test */
 	for (i = 0; i < BUFSIZE; i++)
 		writebuf[i] = i & 0xFF;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]