-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1) added button "Test Connection" to make a news server connection te…
…st from web-interface; 2) improved timeout handling when connecting to news servers which have multiple addresses; 3) improved error handling when communicating with secure servers (do not trying to send quit-command if connection could not be established or was interrupted; this avoids unnecessary timeout)
- Loading branch information
hugbug
committed
Mar 31, 2015
1 parent
2390b58
commit 1552194
Showing
10 changed files
with
259 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* This file is part of nzbget | ||
* | ||
* Copyright (C) 2004 Sven Henkel <[email protected]> | ||
* Copyright (C) 2007-2014 Andrey Prygunkov <[email protected]> | ||
* Copyright (C) 2007-2015 Andrey Prygunkov <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -61,8 +61,31 @@ class Connection | |
bool m_bSuppressErrors; | ||
char m_szRemoteAddr[20]; | ||
int m_iTotalBytesRead; | ||
bool m_bBroken; | ||
|
||
struct SockAddr | ||
{ | ||
int ai_family; | ||
int ai_socktype; | ||
int ai_protocol; | ||
bool operator==(const SockAddr& rhs) const | ||
{ return memcmp(this, &rhs, sizeof(SockAddr)) == 0; } | ||
}; | ||
|
||
#ifndef DISABLE_TLS | ||
TLSSocket* m_pTLSSocket; | ||
class ConTLSSocket: public TLSSocket | ||
{ | ||
private: | ||
Connection* m_pOwner; | ||
protected: | ||
virtual void PrintError(const char* szErrMsg) { m_pOwner->PrintError(szErrMsg); } | ||
public: | ||
ConTLSSocket(SOCKET iSocket, bool bIsClient, const char* szCertFile, | ||
const char* szKeyFile, const char* szCipher, Connection* pOwner): | ||
TLSSocket(iSocket, bIsClient, szCertFile, szKeyFile, szCipher), m_pOwner(pOwner) {} | ||
}; | ||
|
||
ConTLSSocket* m_pTLSSocket; | ||
bool m_bTLSError; | ||
#endif | ||
#ifndef HAVE_GETADDRINFO | ||
|
@@ -73,6 +96,7 @@ class Connection | |
|
||
Connection(SOCKET iSocket, bool bTLS); | ||
void ReportError(const char* szMsgPrefix, const char* szMsgArg, bool PrintErrCode, int herrno); | ||
virtual void PrintError(const char* szErrMsg); | ||
bool DoConnect(); | ||
bool DoDisconnect(); | ||
bool InitSocketOpts(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* This file is part of nzbget | ||
* | ||
* Copyright (C) 2008-2013 Andrey Prygunkov <[email protected]> | ||
* Copyright (C) 2008-2015 Andrey Prygunkov <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -283,6 +283,8 @@ TLSSocket::~TLSSocket() | |
|
||
void TLSSocket::ReportError(const char* szErrMsg) | ||
{ | ||
char szMessage[1024]; | ||
|
||
#ifdef HAVE_LIBGNUTLS | ||
const char* errstr = gnutls_strerror(m_iRetCode); | ||
if (m_bSuppressErrors) | ||
|
@@ -291,7 +293,9 @@ void TLSSocket::ReportError(const char* szErrMsg) | |
} | ||
else | ||
{ | ||
error("%s: %s", szErrMsg, errstr); | ||
snprintf(szMessage, sizeof(szMessage), "%s: %s", szErrMsg, errstr); | ||
szMessage[sizeof(szMessage) - 1] = '\0'; | ||
PrintError(szMessage); | ||
} | ||
#endif /* HAVE_LIBGNUTLS */ | ||
|
||
|
@@ -311,16 +315,23 @@ void TLSSocket::ReportError(const char* szErrMsg) | |
} | ||
else if (errcode != 0) | ||
{ | ||
error("%s: %s", szErrMsg, errstr); | ||
snprintf(szMessage, sizeof(szMessage), "%s: %s", szErrMsg, errstr); | ||
szMessage[sizeof(szMessage) - 1] = '\0'; | ||
PrintError(szMessage); | ||
} | ||
else | ||
{ | ||
error("%s", szErrMsg); | ||
PrintError(szErrMsg); | ||
} | ||
} while (errcode); | ||
#endif /* HAVE_OPENSSL */ | ||
} | ||
|
||
void TLSSocket::PrintError(const char* szErrMsg) | ||
{ | ||
error("%s", szErrMsg); | ||
} | ||
|
||
bool TLSSocket::Start() | ||
{ | ||
#ifdef HAVE_LIBGNUTLS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* This file is part of nzbget | ||
* | ||
* Copyright (C) 2008-2013 Andrey Prygunkov <[email protected]> | ||
* Copyright (C) 2008-2015 Andrey Prygunkov <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -46,9 +46,12 @@ class TLSSocket | |
|
||
void ReportError(const char* szErrMsg); | ||
|
||
protected: | ||
virtual void PrintError(const char* szErrMsg); | ||
|
||
public: | ||
TLSSocket(SOCKET iSocket, bool bIsClient, const char* szCertFile, const char* szKeyFile, const char* szCipher); | ||
~TLSSocket(); | ||
virtual ~TLSSocket(); | ||
static void Init(); | ||
static void Final(); | ||
bool Start(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* This file is part of nzbget | ||
* | ||
* Copyright (C) 2004 Sven Henkel <[email protected]> | ||
* Copyright (C) 2007-2013 Andrey Prygunkov <[email protected]> | ||
* Copyright (C) 2007-2015 Andrey Prygunkov <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -99,8 +99,8 @@ bool NNTPConnection::Authenticate() | |
{ | ||
if (strlen(m_pNewsServer->GetUser()) == 0 || strlen(m_pNewsServer->GetPassword()) == 0) | ||
{ | ||
error("%c%s (%s) requested authorization but username/password are not set in settings", | ||
toupper(m_pNewsServer->GetName()[0]), m_pNewsServer->GetName() + 1, m_pNewsServer->GetHost()); | ||
ReportError("Could not connect to %s: server requested authorization but username/password are not set in settings", | ||
m_pNewsServer->GetHost(), false, 0); | ||
m_bAuthError = true; | ||
return false; | ||
} | ||
|
@@ -264,7 +264,10 @@ bool NNTPConnection::Disconnect() | |
{ | ||
if (m_eStatus == csConnected) | ||
{ | ||
Request("quit\r\n"); | ||
if (!m_bBroken) | ||
{ | ||
Request("quit\r\n"); | ||
} | ||
free(m_szActiveGroup); | ||
m_szActiveGroup = NULL; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* This file is part of nzbget | ||
* | ||
* Copyright (C) 2004 Sven Henkel <[email protected]> | ||
* Copyright (C) 2007-2008 Andrey Prygunkov <[email protected]> | ||
* Copyright (C) 2007-2015 Andrey Prygunkov <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -53,6 +53,7 @@ class NNTPConnection : public Connection | |
const char* Request(const char* req); | ||
const char* JoinGroup(const char* grp); | ||
bool GetAuthError() { return m_bAuthError; } | ||
|
||
}; | ||
|
||
#endif | ||
|
Oops, something went wrong.