[pan2/testing: 219/279] fixed stupid ssl multithread pthread bug
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2/testing: 219/279] fixed stupid ssl multithread pthread bug
- Date: Sat, 3 Dec 2011 22:39:59 +0000 (UTC)
commit d2a0345a62449aa8d656e1bed531c5b119d20f69
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date: Sun Oct 23 03:30:47 2011 +0200
fixed stupid ssl multithread pthread bug
pan/gui/header-pane.cc | 9 ++++--
pan/gui/pan.cc | 1 -
pan/gui/prefs-ui.cc | 13 +++++----
pan/tasks/socket-impl-main.cc | 52 ++++++++++++++++++++++++++++++++++++-
pan/tasks/socket-impl-openssl.cc | 42 +++---------------------------
pan/tasks/socket-impl-openssl.h | 1 +
6 files changed, 69 insertions(+), 49 deletions(-)
---
diff --git a/pan/gui/header-pane.cc b/pan/gui/header-pane.cc
index c8bd6ee..47df21c 100644
--- a/pan/gui/header-pane.cc
+++ b/pan/gui/header-pane.cc
@@ -267,6 +267,7 @@ HeaderPane :: render_subject (GtkTreeViewColumn * ,
gpointer user_data)
{
const HeaderPane * self (static_cast<HeaderPane*>(user_data));
+ const Prefs & p(self->_prefs);
const Row * row (dynamic_cast<Row*>(self->_tree_store->get_row (iter)));
CountUnread counter (row);
@@ -278,7 +279,7 @@ HeaderPane :: render_subject (GtkTreeViewColumn * ,
const char * text (a->subject.c_str());
char buf[512];
- bool underlined (false);
+ bool unread (false);
if (counter.unread_children)
{
@@ -289,7 +290,7 @@ HeaderPane :: render_subject (GtkTreeViewColumn * ,
gtk_tree_path_free (path);
if (!expanded) {
- underlined = row->is_read;
+ unread = row->is_read;
snprintf (buf, sizeof(buf), "%s (%lu)", text, counter.unread_children);
text = buf;
}
@@ -298,7 +299,9 @@ HeaderPane :: render_subject (GtkTreeViewColumn * ,
g_object_set (renderer,
"text", text,
"weight", (bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL),
- "underline", (underlined ? PANGO_UNDERLINE_SINGLE : PANGO_UNDERLINE_NONE),
+ "foreground", unread ? p.get_color_str ("score-color-read-fg",TANGO_ORANGE).c_str() :
+ "black",
+ "background", unread ? p.get_color_str ("score-color-read-bg","white").c_str() : "white",
NULL);
}
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index e8a37a4..5972c1f 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -332,7 +332,6 @@ main (int argc, char *argv[])
// instantiate the queue...
WorkerPool worker_pool (4, true);
-// GIOChannelSocket::Creator socket_creator;
SocketCreator socket_creator;
Queue queue (data, data, &socket_creator, worker_pool,
diff --git a/pan/gui/prefs-ui.cc b/pan/gui/prefs-ui.cc
index c7fe83f..c1b142d 100644
--- a/pan/gui/prefs-ui.cc
+++ b/pan/gui/prefs-ui.cc
@@ -637,7 +637,7 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
row = 0;
t = HIG :: workarea_create ();
HIG :: workarea_add_section_title (t, &row, _("Header Pane"));
- HIG :: workarea_add_section_spacer(t, row, 5);
+ HIG :: workarea_add_section_spacer(t, row, 6);
h = gtk_hbox_new (false, PAD);
pan_box_pack_start_defaults (GTK_BOX(h), gtk_label_new (_("Text:")));
pan_box_pack_start_defaults (GTK_BOX(h), new_color_button ("score-color-watched-fg", "black", prefs));
@@ -668,6 +668,12 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
pan_box_pack_start_defaults (GTK_BOX(h), gtk_label_new (_("Background:")));
pan_box_pack_start_defaults (GTK_BOX(h), new_color_button ("score-color-ignored-bg", "black", prefs));
HIG :: workarea_add_row (t, &row, _("Scores of -9999 or less:"), h);
+ h = gtk_hbox_new (false, PAD);
+ pan_box_pack_start_defaults (GTK_BOX(h), gtk_label_new (_("Text:")));
+ pan_box_pack_start_defaults (GTK_BOX(h), new_color_button ("score-color-read-fg", TANGO_ORANGE, prefs));
+ pan_box_pack_start_defaults (GTK_BOX(h), gtk_label_new (_("Background:")));
+ pan_box_pack_start_defaults (GTK_BOX(h), new_color_button ("score-color-read-bg", "white", prefs));
+ HIG :: workarea_add_row (t, &row, _("Read collapsed Thread:"), h);
HIG :: workarea_add_section_divider (t, &row);
HIG :: workarea_add_section_title (t, &row, _("Body Pane"));
HIG :: workarea_add_section_spacer (t, row, 3);
@@ -708,11 +714,6 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
gtk_misc_set_alignment (GTK_MISC(l), 0.0, 0.5);
HIG::workarea_add_row (t, &row, w, l);
-// HIG::workarea_add_section_divider (t, &row);
-// HIG :: workarea_add_section_title (t, &row, _("Attachment Options (Bulk Uploads)"));
-// w = new_check_button (_("Single master reply/followup with body, attachments are replies"), "upload-option-reply-multi", false, prefs);
-// HIG :: workarea_add_wide_control (t, &row, w);
-
HIG :: workarea_finish (t, &row);
gtk_notebook_append_page (GTK_NOTEBOOK(notebook), t, gtk_label_new_with_mnemonic(_("_Upload options")));
diff --git a/pan/tasks/socket-impl-main.cc b/pan/tasks/socket-impl-main.cc
index 43b68b2..a6da35d 100644
--- a/pan/tasks/socket-impl-main.cc
+++ b/pan/tasks/socket-impl-main.cc
@@ -34,6 +34,9 @@
#include <cerrno>
#include <cstring>
+#include <openssl/crypto.h>
+#include <openssl/ssl.h>
+
#include <pan/general/log.h>
#include <pan/general/macros.h>
#include <pan/general/worker-pool.h>
@@ -139,8 +142,53 @@ namespace pan
};
}
-SocketCreator :: SocketCreator() {}
-SocketCreator :: ~SocketCreator() {}
+
+namespace
+{
+ static pthread_mutex_t *lock_cs=0;
+
+ void gio_lock(int mode, int type, const char *file, int line)
+ {
+ if (mode & CRYPTO_LOCK)
+ pthread_mutex_lock(&(lock_cs[type]));
+ else
+ pthread_mutex_unlock(&(lock_cs[type]));
+ }
+
+ void ssl_thread_setup() {
+ lock_cs = (pthread_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
+ for (int i=0; i<CRYPTO_num_locks(); i++)
+ if (pthread_mutex_init(&lock_cs[i],0) != 0)
+ g_warning("error initialing mutex!");
+
+ CRYPTO_set_locking_callback(gio_lock);
+ }
+
+ void ssl_thread_cleanup() {
+ for (int i=0; i<CRYPTO_num_locks(); i++)
+ pthread_mutex_destroy(&lock_cs[i]);
+ CRYPTO_set_locking_callback(0);
+ CRYPTO_set_id_callback(0);
+ OPENSSL_free(lock_cs);
+ }
+}
+
+SocketCreator :: SocketCreator()
+{
+#ifdef HAVE_OPENSSL
+ SSL_library_init();
+ SSL_load_error_strings();
+ /* init static locks for threads */
+ ssl_thread_setup();
+#endif
+
+}
+SocketCreator :: ~SocketCreator()
+{
+#ifdef HAVE_OPENSSL
+ ssl_thread_cleanup();
+#endif
+}
void
SocketCreator :: create_socket (const StringView & host,
diff --git a/pan/tasks/socket-impl-openssl.cc b/pan/tasks/socket-impl-openssl.cc
index e404f5b..1f54b02 100644
--- a/pan/tasks/socket-impl-openssl.cc
+++ b/pan/tasks/socket-impl-openssl.cc
@@ -265,39 +265,8 @@ namespace
unsigned int verify:1;
} GIOSSLChannel;
- pthread_mutex_t *lock_cs;
- void gio_lock(int mode, int type, const char *file, int line)
- {
- if (mode & CRYPTO_LOCK)
- pthread_mutex_lock(&(lock_cs[type]));
- else
- pthread_mutex_unlock(&(lock_cs[type]));
- }
-
- void thread_setup(void) {
-
- lock_cs = (pthread_mutex_t*)malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
- for (int i=0; i<CRYPTO_num_locks(); i++)
- if (pthread_mutex_init(&(lock_cs[i]),0) != 0)
- g_warning("error initialing mutex!");
-
- // CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
- CRYPTO_set_locking_callback(gio_lock);
- }
-
- void thread_cleanup(void) {
-
- CRYPTO_set_locking_callback(0);
- if (lock_cs)
- {
- for (int i=0; i<CRYPTO_num_locks(); i++)
- if (&lock_cs[i]) pthread_mutex_destroy(&lock_cs[i]);
- if (lock_cs) free(lock_cs);
- }
- }
-
- /* FIXME todo: real verify + UI ! */
+ /* FIXME todo: real verify ! */
gboolean ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
{
// if (SSL_get_verify_result(ssl) != X509_V_OK) {
@@ -344,7 +313,7 @@ namespace
g_io_channel_unref(chan->giochan);
SSL_free(chan->ssl);
SSL_CTX_free(chan->ctx);
- thread_cleanup();
+// thread_cleanup();
g_free(chan);
}
}
@@ -407,9 +376,6 @@ namespace
SSL_CTX* ssl_init(void)
{
- SSL_library_init();
- SSL_load_error_strings();
-
SSL_CTX* ctx (SSL_CTX_new(SSLv3_client_method()));
return ctx;
}
@@ -804,6 +770,8 @@ GIOChannelSocketSSL :: ssl_get_iochannel(GIOChannel *handle, gboolean verify)
}
chan = g_new0(GIOSSLChannel, 1);
+ if (!chan) return 0;
+
chan->fd = fd;
chan->giochan = handle;
chan->ssl = ssl;
@@ -817,7 +785,7 @@ GIOChannelSocketSSL :: ssl_get_iochannel(GIOChannel *handle, gboolean verify)
if (ssl_handshake(gchan))
{
- thread_setup();
+// thread_setup();
return gchan;
}
return 0;
diff --git a/pan/tasks/socket-impl-openssl.h b/pan/tasks/socket-impl-openssl.h
index 48d3017..b5d9138 100644
--- a/pan/tasks/socket-impl-openssl.h
+++ b/pan/tasks/socket-impl-openssl.h
@@ -72,6 +72,7 @@ namespace pan
DoResult do_write ();
GIOChannel * create_channel (const StringView& host_in, int port, std::string& setme_err);
+ void gio_lock(int mode, int type, const char *file, int line);
private:
GIOChannel* ssl_get_iochannel(GIOChannel *handle, gboolean verify=true);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]