diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2012-01-20 06:01:27 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2012-01-20 06:01:27 +0000 |
commit | 430f45f16d2c4e4b610aa347869a53eb225acd20 (patch) | |
tree | 748078683d549784a4edadeeb36f9149ea972abc /libsylph | |
parent | 82acd302b6c178d1068535ecfbeaeecdae1bd57e (diff) |
supported NNTP over SOCKS porxy.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3016 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/news.c | 26 | ||||
-rw-r--r-- | libsylph/nntp.c | 53 | ||||
-rw-r--r-- | libsylph/nntp.h | 16 |
3 files changed, 81 insertions, 14 deletions
diff --git a/libsylph/news.c b/libsylph/news.c index 5a6afc14..c4814dd2 100644 --- a/libsylph/news.c +++ b/libsylph/news.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2009 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -47,6 +47,7 @@ #if USE_SSL # include "ssl.h" #endif +#include "socks.h" #define NNTP_PORT 119 #if USE_SSL @@ -80,12 +81,14 @@ static gint news_scan_group (Folder *folder, #if USE_SSL static Session *news_session_new (const gchar *server, gushort port, + SocksInfo *socks_info, const gchar *userid, const gchar *passwd, SSLType ssl_type); #else static Session *news_session_new (const gchar *server, gushort port, + SocksInfo *socks_info, const gchar *userid, const gchar *passwd); #endif @@ -203,10 +206,12 @@ static void news_folder_init(Folder *folder, const gchar *name, #if USE_SSL static Session *news_session_new(const gchar *server, gushort port, + SocksInfo *socks_info, const gchar *userid, const gchar *passwd, SSLType ssl_type) #else static Session *news_session_new(const gchar *server, gushort port, + SocksInfo *socks_info, const gchar *userid, const gchar *passwd) #endif { @@ -218,9 +223,9 @@ static Session *news_session_new(const gchar *server, gushort port, log_message(_("creating NNTP connection to %s:%d ...\n"), server, port); #if USE_SSL - session = nntp_session_new(server, port, buf, userid, passwd, ssl_type); + session = nntp_session_new_full(server, port, socks_info, buf, userid, passwd, ssl_type); #else - session = nntp_session_new(server, port, buf, userid, passwd); + session = nntp_session_new_full(server, port, socks_info, buf, userid, passwd); #endif return session; @@ -230,6 +235,7 @@ static Session *news_session_new_for_folder(Folder *folder) { Session *session; PrefsAccount *ac; + SocksInfo *socks_info = NULL; const gchar *userid = NULL; gchar *passwd = NULL; gushort port; @@ -246,16 +252,24 @@ static Session *news_session_new_for_folder(Folder *folder) passwd = input_query_password(ac->nntp_server, userid); } + if (ac->use_socks && ac->use_socks_for_recv && ac->proxy_host) { + socks_info = socks_info_new(ac->socks_type, ac->proxy_host, ac->proxy_port, ac->use_proxy_auth ? ac->proxy_name : NULL, ac->use_proxy_auth ? ac->proxy_pass : NULL); + } + #if USE_SSL port = ac->set_nntpport ? ac->nntpport : ac->ssl_nntp ? NNTPS_PORT : NNTP_PORT; - session = news_session_new(ac->nntp_server, port, userid, passwd, - ac->ssl_nntp); + session = news_session_new(ac->nntp_server, port, socks_info, + userid, passwd, ac->ssl_nntp); #else port = ac->set_nntpport ? ac->nntpport : NNTP_PORT; - session = news_session_new(ac->nntp_server, port, userid, passwd); + session = news_session_new(ac->nntp_server, port, socks_info, + userid, passwd); #endif + if (socks_info) + socks_info_free(socks_info); + g_free(passwd); return session; diff --git a/libsylph/nntp.c b/libsylph/nntp.c index d52a4a70..daed4ff1 100644 --- a/libsylph/nntp.c +++ b/libsylph/nntp.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -32,6 +32,7 @@ #if USE_SSL # include "ssl.h" #endif +#include "socks.h" static gint verbose = 1; @@ -53,25 +54,47 @@ static gint nntp_gen_command (NNTPSession *session, #if USE_SSL -Session *nntp_session_new(const gchar *server, gushort port, gchar *buf, - const gchar *userid, const gchar *passwd, - SSLType ssl_type) +Session *nntp_session_new_full(const gchar *server, gushort port, + SocksInfo *socks_info, gchar *buf, + const gchar *userid, const gchar *passwd, + SSLType ssl_type) #else -Session *nntp_session_new(const gchar *server, gushort port, gchar *buf, - const gchar *userid, const gchar *passwd) +Session *nntp_session_new_full(const gchar *server, gushort port, + SocksInfo *socks_info, gchar *buf, + const gchar *userid, const gchar *passwd) #endif { NNTPSession *session; SockInfo *sock; + const gchar *server_; + gushort port_; + + if (socks_info) { + server_ = socks_info->proxy_host; + port_ = socks_info->proxy_port; + } else { + server_ = server; + port_ = port; + } - if ((sock = sock_connect(server, port)) == NULL) { + if ((sock = sock_connect(server_, port_)) == NULL) { log_warning(_("Can't connect to NNTP server: %s:%d\n"), server, port); return NULL; } + if (socks_info) { + if (socks_connect(sock, server, port, socks_info) < 0) { + log_warning("Can't establish SOCKS connection: %s:%d\n", + server, port); + return NULL; + } + } + #if USE_SSL if (ssl_type == SSL_TUNNEL && !ssl_init_socket(sock)) { + log_warning("Can't establish NNTP session with: %s:%d\n", + server, port); sock_close(sock); return NULL; } @@ -130,6 +153,22 @@ Session *nntp_session_new(const gchar *server, gushort port, gchar *buf, return SESSION(session); } +#if USE_SSL +Session *nntp_session_new(const gchar *server, gushort port, gchar *buf, + const gchar *userid, const gchar *passwd, + SSLType ssl_type) +{ + return nntp_session_new_full(server, port, NULL, buf, userid, passwd, + ssl_type); +} +#else +Session *nntp_session_new(const gchar *server, gushort port, gchar *buf, + const gchar *userid, const gchar *passwd) +{ + return nntp_session_new_full(server, port, NULL, buf, userid, passwd); +} +#endif + static void nntp_session_destroy(Session *session) { NNTPSession *nntp_session = NNTP_SESSION(session); diff --git a/libsylph/nntp.h b/libsylph/nntp.h index 55fbaa68..045fae74 100644 --- a/libsylph/nntp.h +++ b/libsylph/nntp.h @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,6 +24,7 @@ #if USE_SSL # include "ssl.h" #endif +#include "socks.h" typedef struct _NNTPSession NNTPSession; @@ -59,12 +60,25 @@ Session *nntp_session_new (const gchar *server, const gchar *userid, const gchar *passwd, SSLType ssl_type); +Session *nntp_session_new_full (const gchar *server, + gushort port, + SocksInfo *socks_info, + gchar *buf, + const gchar *userid, + const gchar *passwd, + SSLType ssl_type); #else Session *nntp_session_new (const gchar *server, gushort port, gchar *buf, const gchar *userid, const gchar *passwd); +Session *nntp_session_new_full (const gchar *server, + gushort port, + SocksInfo *socks_info, + gchar *buf, + const gchar *userid, + const gchar *passwd); #endif gint nntp_group (NNTPSession *session, |