diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2005-06-22 21:08:21 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2005-06-22 21:08:21 +0000 |
commit | ae8f8a570067e1e1e65bfac3f60c7bec0d4faf31 (patch) | |
tree | 2100374f5270c4dd08f43b47e36c249bf347db4f /src | |
parent | 5e8b47f187bcb26b187694b915177abe431c683b (diff) | |
download | weechat-ae8f8a570067e1e1e65bfac3f60c7bec0d4faf31.zip |
gnutls code compiled according to pre-processor var HAVE_GNUTLS
Diffstat (limited to 'src')
-rw-r--r-- | src/common/weechat.c | 11 | ||||
-rw-r--r-- | src/common/weechat.h | 6 | ||||
-rw-r--r-- | src/gui/curses/Makefile.am | 2 | ||||
-rw-r--r-- | src/irc/irc-server.c | 47 | ||||
-rw-r--r-- | src/irc/irc.h | 14 |
5 files changed, 72 insertions, 8 deletions
diff --git a/src/common/weechat.c b/src/common/weechat.c index 427408564..d6ddb3a24 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -47,7 +47,10 @@ #include <sys/stat.h> #include <time.h> #include <signal.h> + +#ifdef HAVE_GNUTLS #include <gnutls/gnutls.h> +#endif #ifdef HAVE_ICONV #include <iconv.h> @@ -75,7 +78,9 @@ char *local_charset = NULL; /* local charset, for example: ISO-8859-1 */ int server_cmd_line; /* at least one server on WeeChat command line */ +#ifdef HAVE_GNUTLS gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */ +#endif /* @@ -521,9 +526,11 @@ wee_init_vars () msgq_last_msg = NULL; /* init gnutls */ + #ifdef HAVE_GNUTLS gnutls_global_init (); gnutls_certificate_allocate_credentials (&gnutls_xcred); gnutls_certificate_set_x509_trust_file (gnutls_xcred, "ca.pem", GNUTLS_X509_FMT_PEM); + #endif } /* @@ -617,8 +624,12 @@ wee_shutdown (int return_code) if (local_charset) free (local_charset); alias_free_all (); + + #ifdef HAVE_GNUTLS gnutls_certificate_free_credentials (gnutls_xcred); gnutls_global_deinit(); + #endif + exit (return_code); } diff --git a/src/common/weechat.h b/src/common/weechat.h index 58bb85717..33160a52f 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -27,7 +27,10 @@ #include <stdio.h> #include <sys/time.h> + +#ifdef HAVE_GNUTLS #include <gnutls/gnutls.h> +#endif #if defined(ENABLE_NLS) && !defined(_) #include <locale.h> @@ -108,7 +111,10 @@ extern int quit_weechat; extern char *weechat_home; extern char *local_charset; + +#ifdef HAVE_GNUTLS extern gnutls_certificate_credentials gnutls_xcred; +#endif extern void wee_log_printf (char *, ...); extern void wee_dump (int); diff --git a/src/gui/curses/Makefile.am b/src/gui/curses/Makefile.am index 7f8c0b001..01eaaa35d 100644 --- a/src/gui/curses/Makefile.am +++ b/src/gui/curses/Makefile.am @@ -24,7 +24,7 @@ weechat_curses_LDADD = ../lib_weechat_gui_common.a \ ../../irc/lib_weechat_irc.a \ $(NCURSES_LIBS) \ ../../plugins/lib_weechat_plugins.a $(PLUGINS_LIBS) \ - -lgnutls + $(GNUTLS_LIBS) weechat_curses_SOURCES = gui-display.c \ gui-input.c diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 0e0c44b0b..f51837b7c 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -38,7 +38,10 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> + +#ifdef HAVE_GNUTLS #include <gnutls/gnutls.h> +#endif #include "../common/weechat.h" #include "irc.h" @@ -87,6 +90,9 @@ server_init (t_irc_server *server) server->child_write = -1; server->sock = -1; server->is_connected = 0; + #ifdef HAVE_GNUTLS + server->ssl_connected = 0; + #endif server->unterminated_message = NULL; server->nick = NULL; server->reconnect_start = 0; @@ -383,9 +389,11 @@ server_send (t_irc_server *server, char *buffer, int size_buf) if (!server) return -1; - if (server->ssl) + #ifdef HAVE_GNUTLS + if (server->ssl_connected) return gnutls_record_send (server->gnutls_sess, buffer, size_buf); else + #endif return send (server->sock, buffer, size_buf, 0); } @@ -660,9 +668,11 @@ server_recv (t_irc_server *server) if (!server) return; - if (server->ssl) + #ifdef HAVE_GNUTLS + if (server->ssl_connected) num_read = gnutls_record_recv (server->gnutls_sess, buffer, sizeof (buffer) - 2); else + #endif num_read = recv (server->sock, buffer, sizeof (buffer) - 2, 0); if (num_read > 0) @@ -721,12 +731,16 @@ server_close_connection (t_irc_server *server) /* close network socket */ if (server->sock != -1) { - if (server->ssl) + #ifdef HAVE_GNUTLS + if (server->ssl_connected) gnutls_bye (server->gnutls_sess, GNUTLS_SHUT_RDWR); + #endif close (server->sock); server->sock = -1; - if (server->ssl) + #ifdef HAVE_GNUTLS + if (server->ssl_connected) gnutls_deinit (server->gnutls_sess); + #endif } /* free any pending message */ @@ -738,6 +752,9 @@ server_close_connection (t_irc_server *server) /* server is now disconnected */ server->is_connected = 0; + #ifdef HAVE_GNUTLS + server->ssl_connected = 0; + #endif } /* @@ -776,7 +793,8 @@ server_child_read (t_irc_server *server) /* connection OK */ case '0': /* enable SSL if asked */ - if (server->ssl) + #ifdef HAVE_GNUTLS + if (server->ssl_connected) { gnutls_transport_set_ptr (server->gnutls_sess, (gnutls_transport_ptr) server->sock); if (gnutls_handshake (server->gnutls_sess) < 0) @@ -790,6 +808,7 @@ server_child_read (t_irc_server *server) return; } } + #endif /* kill child and login to server */ server_kill_child (server); irc_login (server); @@ -878,8 +897,20 @@ server_connect (t_irc_server *server) { int child_pipe[2], set; pid_t pid; + #ifdef HAVE_GNUTLS const int cert_type_prio[] = { GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0 }; - + #endif + + #ifndef HAVE_GNUTLS + if (server->ssl) + { + irc_display_prefix (server->buffer, PREFIX_ERROR); + gui_printf (server->buffer, + _("%s cannot connect with SSL since WeeChat was not built " + "with GNUtls support\n"), WEECHAT_ERROR); + return 0; + } + #endif irc_display_prefix (server->buffer, PREFIX_INFO); gui_printf (server->buffer, _("%s: connecting to %s:%d%s...\n"), @@ -893,6 +924,8 @@ server_connect (t_irc_server *server) server_close_connection (server); /* init SSL if asked */ + #ifdef HAVE_GNUTLS + server->ssl_connected = 0; if (server->ssl) { if (gnutls_init (&server->gnutls_sess, GNUTLS_CLIENT) != 0) @@ -905,7 +938,9 @@ server_connect (t_irc_server *server) gnutls_set_default_priority (server->gnutls_sess); gnutls_certificate_type_set_priority (server->gnutls_sess, cert_type_prio); gnutls_credentials_set (server->gnutls_sess, GNUTLS_CRD_CERTIFICATE, gnutls_xcred); + server->ssl_connected = 1; } + #endif /* create pipe for child process */ if (pipe (child_pipe) < 0) diff --git a/src/irc/irc.h b/src/irc/irc.h index 35f61c69e..6676b0fb3 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -21,10 +21,18 @@ #ifndef __WEECHAT_IRC_H #define __WEECHAT_IRC_H 1 +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <time.h> #include <sys/time.h> #include <sys/types.h> + +#ifdef HAVE_GNUTLS #include <gnutls/gnutls.h> +#endif + #include "../gui/gui.h" /* prefixes for chat window */ @@ -156,8 +164,12 @@ struct t_irc_server int child_read; /* to read into child pipe */ int child_write; /* to write into child pipe */ int sock; /* socket for server */ - gnutls_session gnutls_sess; /* gnutls session (only if SSL is used) */ int is_connected; /* 1 if WeeChat is connected to server */ + #ifdef HAVE_GNUTLS + int ssl_connected; /* = 1 if connected with SSL */ + gnutls_session gnutls_sess; /* gnutls session (only if SSL is used) */ + #endif + char *unterminated_message; /* beginning of a message in input buf */ char *nick; /* current nickname */ time_t reconnect_start; /* this time + delay = reconnect time */ |