+2008-02-09 Dan Winship <danw@gnome.org>
+
+ * 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.
+
2008-02-08 Dan Winship <danw@gnome.org>
* libsoup/soup-message-headers.c (SoupMessageHeadersIter)
/* 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,
/* 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,
};
/* 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,
/* bit 0 is left-most in byte */
-static int bytebit[] = {
+static const int bytebit[] = {
0200,0100,040,020,010,04,02,01
};
**/
/* 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"
};
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 */
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;
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);
}
}
*
* 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
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,
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;
-
- return TRUE;
-
-THROW_CREATE_ERROR:
- if (dh_params) {
- gnutls_dh_params_deinit (dh_params);
- dh_params = NULL;
+ static volatile gsize inited_dh_params = 0;
+
+ 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;
}
/**
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;
return NULL;
}
-static gboolean soup_gnutls_inited = FALSE;
-
#ifdef GCRY_THREAD_OPTION_PTHREAD_IMPL
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#endif
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);
+ }
}
/**
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);
{
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);
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()
#ifndef HAVE_SSL
-gboolean soup_ssl_supported = FALSE;
+const gboolean soup_ssl_supported = FALSE;
GIOChannel *
soup_ssl_wrap_iochannel (GIOChannel *sock, SoupSSLType type,
* network and internal errors.
**/
-static struct {
+static const struct {
guint code;
const char *phrase;
} reason_phrases [] = {
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,
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;