[pan2: 251/268] * a few gnutls fixes * merged back from merge master-test + intermediate fixes



commit ff486c2b4d831761718b2d98b17afa838aeb1572
Author: Heinrich MÃller <henmull src gnome org>
Date:   Fri Dec 23 17:49:44 2011 +0100

    * a few gnutls fixes
    * merged back from merge master-test + intermediate fixes

 pan/data/cert-store.cc        |   85 +++++++++++++++++++++++-----------------
 pan/data/cert-store.h         |    1 +
 pan/data/data.h               |    4 --
 pan/gui/group-prefs-dialog.cc |    6 ++-
 pan/gui/gui.cc                |   13 +++++-
 pan/gui/hig.cc                |    3 +
 pan/gui/server-ui.cc          |   31 ++++++---------
 7 files changed, 80 insertions(+), 63 deletions(-)
---
diff --git a/pan/data/cert-store.cc b/pan/data/cert-store.cc
index 3c92d5a..4d98d8d 100644
--- a/pan/data/cert-store.cc
+++ b/pan/data/cert-store.cc
@@ -162,60 +162,73 @@ namespace pan
 
   }
 
-  int
-  CertStore :: get_all_certs_from_disk()
+  bool
+  CertStore :: import_from_file (const Quark& server, const char* fn)
   {
 
-    int cnt(0);
-    quarks_t servers(_data.get_servers());
-    int ret(0);
     size_t filelen;
     char * buf;
 
-    foreach_const(quarks_t, servers, it)
-    {
-      Data::Server* s(_data.find_server(*it));
-      if (!s) continue;
-      const char* filename(s->cert.c_str());
-      if (!filename) continue;
+    Data::Server* s(_data.find_server(server));
+    if (!s) return false;
 
-      FILE * fp = fopen(filename, "rb");
-      if (!fp) continue;
+    const char* filename(fn ? fn : s->cert.c_str());
+    if (!filename) return false;
 
-      fseek (fp, 0, SEEK_END);
-      filelen = ftell (fp);
-      fseek (fp, 0, SEEK_SET);
-      buf = new char[filelen];
-      fread (buf, sizeof(char), filelen, fp);
+    FILE * fp = fopen(filename, "rb");
+    if (!fp) return false;
 
-      gnutls_datum_t in;
-      in.data = (unsigned char*)buf;
-      in.size = filelen;
-      gnutls_x509_crt_t cert;
-      gnutls_x509_crt_init(&cert);
-      gnutls_x509_crt_import(cert, &in, GNUTLS_X509_FMT_PEM);
+    fseek (fp, 0, SEEK_END);
+    filelen = ftell (fp);
+    fseek (fp, 0, SEEK_SET);
+    buf = new char[filelen];
+    fread (buf, sizeof(char), filelen, fp);
 
-      delete buf;
+    gnutls_datum_t in;
+    in.data = (unsigned char*)buf;
+    in.size = filelen;
+    gnutls_x509_crt_t cert;
+    gnutls_x509_crt_init(&cert);
+    gnutls_x509_crt_import(cert, &in, GNUTLS_X509_FMT_PEM);
 
-      ret = gnutls_certificate_set_x509_trust(_creds, &cert, 1);
-      if (ret > 0) cnt += ret; else goto fail;
+    delete buf;
 
-      _certs.insert(*it);
-      _cert_to_server[*it] = cert;
+    int ret = gnutls_certificate_set_x509_trust(_creds, &cert, 1);
 
-      continue;
+    if (ret < 0) goto fail;
 
-      fail:
-        s->cert.clear();
-        gnutls_x509_crt_deinit (cert);
-        _data.save_server_info(*it);
-    }
+    _certs.insert(server);
+    _cert_to_server[server] = cert;
 
-    // get certs from ssl certs directory
+    return true;
+
+    fail:
+      s->cert.clear();
+      gnutls_x509_crt_deinit (cert);
+      _data.save_server_info(server);
+
+    return false;
+
+  }
+
+  int
+  CertStore :: get_all_certs_from_disk()
+  {
+
+    int cnt(0);
+    quarks_t servers(_data.get_servers());
+    int ret(0);
+    size_t filelen;
+    char * buf;
     GError* err(NULL);
 
+    foreach_const(quarks_t, servers, it)
+      if (import_from_file(*it)) ++cnt;
+
+    // get certs from ssl certs directory
     const char * ssldir = getenv("SSL_CERT_DIR");
     if (!ssldir) ssldir = getenv("SSL_DIR");
+    if (!ssldir) return cnt;
 
     GDir * dir = g_dir_open (ssldir, 0, &err);
     if (err != NULL)
diff --git a/pan/data/cert-store.h b/pan/data/cert-store.h
index 9554ecc..918f6fb 100644
--- a/pan/data/cert-store.h
+++ b/pan/data/cert-store.h
@@ -65,6 +65,7 @@ namespace pan
     public:
 
       int get_all_certs_from_disk();
+      bool import_from_file (const Quark& server, const char* fn = 0);
 
       bool in_blacklist (const Quark& s)
       {
diff --git a/pan/data/data.h b/pan/data/data.h
index d0ab7cf..3ba0db5 100644
--- a/pan/data/data.h
+++ b/pan/data/data.h
@@ -320,10 +320,6 @@ namespace pan
 
     public:
 
-      virtual void fire_article_flag_changed (const Article* a, const Quark& group);
-
-    public:
-
       virtual void fire_article_flag_changed (articles_t& a, const Quark& group);
 
     /*****************************************************************
diff --git a/pan/gui/group-prefs-dialog.cc b/pan/gui/group-prefs-dialog.cc
index ccc3e59..0582a93 100644
--- a/pan/gui/group-prefs-dialog.cc
+++ b/pan/gui/group-prefs-dialog.cc
@@ -250,8 +250,10 @@ GroupPrefsDialog :: GroupPrefsDialog (Data            & data,
 
   HIG::workarea_add_section_title (t, &row, buf);
     HIG :: workarea_add_section_spacer (t, row, 4);
-    GtkWidget* box = _charset = e_charset_combo_box_new( );
-    e_charset_combo_box_set_charset( E_CHARSET_COMBO_BOX(_charset), _group_prefs.get_string (groups[0], "character-encoding", "UTF-8").c_str());
+    w = _charset = e_charset_combo_box_new( );
+    const char* cs = _group_prefs.get_string (groups[0], "character-encoding", "UTF-8").c_str();
+    e_charset_combo_box_set_charset( E_CHARSET_COMBO_BOX(w), cs ? cs : "");
+
     HIG :: workarea_add_row (t, &row, _("Character _encoding:"), w);
 
     w = _save_path = file_entry_new (_("Directory for Saving Attachments"));
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 4e133c0..f97343b 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -1147,9 +1147,18 @@ GUI :: do_flag_off ()
   do_flag(false);
 }
 
-void GUI :: do_flag (bool t)
+void
+GUI :: do_flag (bool on)
 {
-
+  std::vector<const Article*> v(_header_pane->get_full_selection_v());
+  g_return_if_fail(!v.empty());
+  foreach (std::vector<const Article*>,v,it)
+  {
+    Article* a((Article*)*it);
+    a->set_flag(on);
+  }
+  const Quark& g(_header_pane->get_group());
+  _data.fire_article_flag_changed(v, g);
 }
 
 
diff --git a/pan/gui/hig.cc b/pan/gui/hig.cc
index 5fc420f..b0ad223 100644
--- a/pan/gui/hig.cc
+++ b/pan/gui/hig.cc
@@ -22,6 +22,8 @@
 #include <gtk/gtk.h>
 #include "hig.h"
 
+#include <iostream>
+
 using namespace pan;
 
 /***
@@ -135,6 +137,7 @@ HIG :: workarea_add_control (GtkWidget   * table,
                               int           row,
                               GtkWidget   * control)
 {
+  std::cerr<<"table attach "<<table<<" "<<control<<"\n";
   gtk_table_attach (GTK_TABLE(table), control, 3, 4, row, row+1, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), (GtkAttachOptions)0, 0, 0);
 }
 
diff --git a/pan/gui/server-ui.cc b/pan/gui/server-ui.cc
index 8b58427..134117a 100644
--- a/pan/gui/server-ui.cc
+++ b/pan/gui/server-ui.cc
@@ -759,25 +759,18 @@ namespace
     const Quark selected_server (get_selected_server (d));
     CertStore& store (d->data.get_certstore());
 
-//    if (!ret.empty() )
-//    {
-//      std::string addr; int port;
-//      FILE *fp = fopen(ret.c_str(),"rb");
-//      X509 *x;
-//      if (!fp) goto _err;
-//      x = X509_new();
-//      if (!x) { fclose(fp); goto _err; }
-//      PEM_read_X509(fp,&x, 0, 0);
-//      fclose(fp);
-//      d->data.get_server_addr(selected_server, addr, port);
-//      if (!store.add(x,selected_server))
-//      {
-//      _err:
-//        Log::add_err_va("Error adding certificate of server '%s' to CertStore. Check the console output!", addr.c_str());
-//        file::print_file_info(std::cerr,ret.c_str());
-//      }
-//      sec_tree_view_refresh (d);
-//    }
+    if (!ret.empty() )
+    {
+      std::string addr; int port;
+      d->data.get_server_addr(selected_server, addr, port);
+      if (!store.import_from_file(selected_server, ret.c_str()))
+      {
+      _err:
+        Log::add_err_va("Error adding certificate of server '%s' to CertStore. Check the console output!", addr.c_str());
+        file::print_file_info(std::cerr,ret.c_str());
+      }
+      sec_tree_view_refresh (d);
+    }
   }
 
 



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