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/nntp.c | |
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/nntp.c')
-rw-r--r-- | libsylph/nntp.c | 53 |
1 files changed, 46 insertions, 7 deletions
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); |