moved ssl stuff to a seperate file
authorChristoph Hohmann <reboot@gmx.ch>
Fri, 20 Jul 2001 19:43:47 +0000 (19:43 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Fri, 20 Jul 2001 19:43:47 +0000 (19:43 +0000)
ChangeLog.claws
src/Makefile.am
src/inc.c
src/main.c
src/main.h
src/socket.h
src/ssl.c [new file with mode: 0644]
src/ssl.h [new file with mode: 0644]

index 7442f26917dd739237cba968f3b81ab85670a9c7..4217e912fdaaf24b093767605db92bbdb87f2ce1 100644 (file)
@@ -1,3 +1,12 @@
+2001-07-20 [christoph]
+
+       * src/Makefile.am
+       * src/inc.c
+       * src/main.[ch]
+       * src/socket.h
+       * src/ssl.[ch] (new)
+               moved ssl stuff to a seperate file
+
 2001-07-20 [darko]
 
        * src/summaryview.c
 2001-07-20 [darko]
 
        * src/summaryview.c
index 198cbf175ec4c146afa7e996452b1912ebd4a0f8..68d66559939aec8e97ac613b61822d1f9ccf8ca3 100644 (file)
@@ -97,7 +97,8 @@ sylpheed_SOURCES = \
        editvcard.c editvcard.h \
        editjpilot.c editjpilot.h \
        editldap.c editldap.h \
        editvcard.c editvcard.h \
        editjpilot.c editjpilot.h \
        editldap.c editldap.h \
-       editldap_basedn.c editldap_basedn.h
+       editldap_basedn.c editldap_basedn.h \
+       ssl.c ssl.h
 
 EXTRA_DIST = \
        quote_fmt_parse.h \
 
 EXTRA_DIST = \
        quote_fmt_parse.h \
index afbc7e3383a8a885a0530c57c248b54ab439ace6..a5220f2fdf27561d03a51de64e81327b05eadf33 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -581,59 +581,12 @@ static IncState inc_pop3_session_do(IncSession *session)
 
 #ifdef USE_SSL
        if(pop3_state->ac_prefs->pop_ssl) {
 
 #ifdef USE_SSL
        if(pop3_state->ac_prefs->pop_ssl) {
-               X509 *server_cert;
-
-               if(ssl_ctx == NULL) {
-                       log_warning(_("SSL not available\n"));
-
+               if(!ssl_init_socket(sockinfo)) {
                        pop3_automaton_terminate(NULL, atm);
                        automaton_destroy(atm);
 
                        return INC_ERROR;
                }
                        pop3_automaton_terminate(NULL, atm);
                        automaton_destroy(atm);
 
                        return INC_ERROR;
                }
-
-               sockinfo->ssl = SSL_new(ssl_ctx);
-               if(sockinfo->ssl == NULL) {
-                       log_warning(_("Error creating ssl context\n"));
-
-                       pop3_automaton_terminate(NULL, atm);
-                       automaton_destroy(atm);
-
-                       return INC_ERROR;
-               }
-               SSL_set_fd(sockinfo->ssl, sockinfo->sock);
-               if(SSL_connect(sockinfo->ssl) == -1) {
-                       log_warning(_("SSL connect failed\n"));
-
-                       pop3_automaton_terminate(NULL, atm);
-                       automaton_destroy(atm);
-
-                       return INC_ERROR;
-               }
-               
-               /* Get the cipher */
-
-               log_print(_("SSL connection using %s\n"), SSL_get_cipher(sockinfo->ssl));
-  
-               /* Get server's certificate (note: beware of dynamic allocation) */
-
-               if((server_cert = SSL_get_peer_certificate(sockinfo->ssl)) != NULL) {
-                       char *str;
-                       
-                       log_print(_("Server certificate:\n"));
-  
-                       if((str = X509_NAME_oneline(X509_get_subject_name (server_cert),0,0)) != NULL) {
-                               log_print(_("  Subject: %s\n"), str);
-                               free(str);
-                       }
-                       
-                       if((str = X509_NAME_oneline(X509_get_issuer_name  (server_cert),0,0)) != NULL) {
-                               log_print(_("  Issuer: %s\n"), str);
-                               free(str);
-                       }
-
-                       X509_free(server_cert);
-               }
        } else {
                sockinfo->ssl = NULL;
        }
        } else {
                sockinfo->ssl = NULL;
        }
@@ -661,9 +614,7 @@ static IncState inc_pop3_session_do(IncSession *session)
 #endif
 
 #if USE_SSL
 #endif
 
 #if USE_SSL
-       if(sockinfo->ssl) {
-               SSL_free(sockinfo->ssl);
-       }
+       ssl_done_socket(sockinfo);
 #endif
        automaton_destroy(atm);
 
 #endif
        automaton_destroy(atm);
 
index 0fde8f1e0185f97e645e592e3d1e9c0e4456775d..131497ca1fde2e5d9f7446d08aa7c6c9012a3bd6 100644 (file)
 #  include <gpgme.h>
 #endif
 
 #  include <gpgme.h>
 #endif
 
+#if USE_SSL
+#  include "ssl.h"
+#endif
+
 #include "intl.h"
 #include "main.h"
 #include "mainwindow.h"
 #include "intl.h"
 #include "main.h"
 #include "mainwindow.h"
@@ -83,10 +87,6 @@ gboolean debug_mode = FALSE;
 static gint lock_socket = -1;
 static gint lock_socket_tag = 0;
 
 static gint lock_socket = -1;
 static gint lock_socket_tag = 0;
 
-#if USE_SSL
-SSL_CTX *ssl_ctx;
-#endif
-
 static struct Cmd {
        gboolean receive;
        gboolean receive_all;
 static struct Cmd {
        gboolean receive;
        gboolean receive_all;
@@ -238,19 +238,7 @@ int main(int argc, char *argv[])
 #endif
 
 #if USE_SSL
 #endif
 
 #if USE_SSL
-       {
-               SSL_METHOD *meth;
-               
-               SSLeay_add_ssl_algorithms();
-               meth = SSLv2_client_method();
-               SSL_load_error_strings();
-               ssl_ctx = SSL_CTX_new(meth);
-               if(ssl_ctx == NULL) {
-                       debug_print(_("SSL disabled\n"));
-               } else {
-                       debug_print(_("SSL loaded: \n"));
-               }
-       }
+       ssl_init();
 #endif
 
        prefs_common_save_config();
 #endif
 
        prefs_common_save_config();
@@ -299,9 +287,7 @@ int main(int argc, char *argv[])
        gtk_main();
 
 #if USE_SSL
        gtk_main();
 
 #if USE_SSL
-       if(ssl_ctx) {
-               SSL_CTX_free(ssl_ctx);
-       }
+       ssl_done();
 #endif
 
        return 0;
 #endif
 
        return 0;
index dffb2912606a69b1c76803fcccdb175559665ec1..0fb8c56f07294e563fe25a610c0e74b7db329f21 100644 (file)
 #include <glib.h>
 #include <gtk/gtkwidget.h>
 
 #include <glib.h>
 #include <gtk/gtkwidget.h>
 
-#ifdef USE_SSL
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#endif
-
 extern gchar *prog_version;
 extern gchar *startup_dir;
 extern gboolean debug_mode;
 
 extern gchar *prog_version;
 extern gchar *startup_dir;
 extern gboolean debug_mode;
 
-#ifdef USE_SSL
-extern SSL_CTX *ssl_ctx;
-#endif
-
 void app_will_exit     (GtkWidget *widget, gpointer data);
 
 #endif /* __MAIN_H__ */
 void app_will_exit     (GtkWidget *widget, gpointer data);
 
 #endif /* __MAIN_H__ */
index a3a99f3a01891117056b842eac36a579579aa50d..ac06ef74b10753bbbf9905cafbc514988f4d0ea6 100644 (file)
 #  include <pthread.h>
 #endif
 
 #  include <pthread.h>
 #endif
 
+typedef struct _SockInfo       SockInfo;
+
 #if USE_SSL
 #if USE_SSL
-#  include <openssl/crypto.h>
-#  include <openssl/x509.h>
-#  include <openssl/pem.h>
-#  include <openssl/ssl.h>
-#  include <openssl/err.h>
+#  include "ssl.h"
 #endif
 
 #endif
 
-typedef struct _SockInfo       SockInfo;
-
 typedef enum
 {
        CONN_READY,
 typedef enum
 {
        CONN_READY,
diff --git a/src/ssl.c b/src/ssl.c
new file mode 100644 (file)
index 0000000..62fe53a
--- /dev/null
+++ b/src/ssl.c
@@ -0,0 +1,105 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#if USE_SSL
+
+#include "intl.h"
+#include "utils.h"
+#include "ssl.h"
+
+SSL_CTX *ssl_ctx;
+
+void ssl_init() {
+    SSL_METHOD *meth;
+               
+    SSLeay_add_ssl_algorithms();
+    meth = SSLv2_client_method();
+    SSL_load_error_strings();
+    ssl_ctx = SSL_CTX_new(meth);
+    if(ssl_ctx == NULL) {
+       debug_print(_("SSL disabled\n"));
+    } else {
+       debug_print(_("SSL loaded: \n"));
+    }
+}
+
+void ssl_done() {
+    if(ssl_ctx) {
+       SSL_CTX_free(ssl_ctx);
+    }
+}
+
+gboolean ssl_init_socket(SockInfo *sockinfo) {
+    X509 *server_cert;
+
+    if(ssl_ctx == NULL) {
+       log_warning(_("SSL not available\n"));
+
+       return FALSE;
+    }
+
+    sockinfo->ssl = SSL_new(ssl_ctx);
+    if(sockinfo->ssl == NULL) {
+       log_warning(_("Error creating ssl context\n"));
+
+       return FALSE;
+    }
+    SSL_set_fd(sockinfo->ssl, sockinfo->sock);
+    if(SSL_connect(sockinfo->ssl) == -1) {
+       log_warning(_("SSL connect failed\n"));
+
+       return FALSE;
+    }
+
+    /* Get the cipher */
+
+    log_print(_("SSL connection using %s\n"), SSL_get_cipher(sockinfo->ssl));
+
+    /* Get server's certificate (note: beware of dynamic allocation) */
+
+    if((server_cert = SSL_get_peer_certificate(sockinfo->ssl)) != NULL) {
+       char *str;
+       
+       log_print(_("Server certificate:\n"));
+
+       if((str = X509_NAME_oneline(X509_get_subject_name (server_cert),0,0)) != NULL) {
+               log_print(_("  Subject: %s\n"), str);
+               free(str);
+       }
+       
+       if((str = X509_NAME_oneline(X509_get_issuer_name  (server_cert),0,0)) != NULL) {
+               log_print(_("  Issuer: %s\n"), str);
+               free(str);
+       }
+
+       X509_free(server_cert);
+    }
+}
+
+void ssl_done_socket(SockInfo *sockinfo) {
+    if(sockinfo->ssl) {
+       SSL_free(sockinfo->ssl);
+    }
+}
+
+#endif /* USE_SSL */
\ No newline at end of file
diff --git a/src/ssl.h b/src/ssl.h
new file mode 100644 (file)
index 0000000..510843d
--- /dev/null
+++ b/src/ssl.h
@@ -0,0 +1,40 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#if USE_SSL
+
+#ifndef __SSL_H__
+#define __SSL_H__
+
+#include <openssl/crypto.h>
+#include <openssl/x509.h>
+#include <openssl/pem.h>
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+
+#include "socket.h"
+
+void ssl_init();
+void ssl_done();
+gboolean ssl_init_socket(SockInfo *sockinfo);
+void ssl_done_socket(SockInfo *sockinfo);
+
+#endif /* __SSL_H__ */
+
+#endif /* USE_SSL */