Skip to content

Commit

Permalink
Merge branch 'master' into 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
martinknafve committed Nov 18, 2014
2 parents 6348807 + b462490 commit 85d5576
Show file tree
Hide file tree
Showing 117 changed files with 2,932 additions and 2,659 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ Without finding any serious issues:
1. Run all integration tests on supported versions of Windows and the different supported databases.
2. Run all server stress tests
3. Enable Gflags (gflags /p /enable hmailserver.exe) and run all integration tests to check for memory issues
4. Run for at least 2 weeks
4. Run for at least 1 week in production for hMailServer.com
5. Wait for at least 500 downloads of the beta version
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace HM

String sPath = FileUtilities::GetFilePath(sFilename);
String sFileToScan = FileUtilities::GetFileNameFromFullPath(sFilename);
String sTempDir = Utilities::GetWin32TempDirectory();
String sTempDir = IniFileSettings::Instance()->GetTempDirectory();

String sCommandLine;
sCommandLine.Format(_T("%s --database=\"%s\" \"%s\" --tempdir=\"%s\""), scannerExecutable.c_str(), databasePath.c_str(), sFileToScan.c_str(), sTempDir.c_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,8 @@ namespace HM
// so that we're sure that we're doing a clean restore
String sDataDirectory = IniFileSettings::Instance()->GetDataDirectory();

std::set<String> vecExcludes;
FileUtilities::DeleteFilesInDirectory(sDataDirectory);
FileUtilities::DeleteDirectoriesInDirectory(sDataDirectory, vecExcludes);
FileUtilities::DeleteDirectoriesInDirectory(sDataDirectory);

String errorMessage;
FileUtilities::CopyDirectory(sDirContainingDataFiles, sDataDirectory, errorMessage);
Expand Down
82 changes: 45 additions & 37 deletions hmailserver/source/Server/Common/Application/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ namespace HM
We pre-create one connection per protocol, so we set the counters to -1 here.
*/
SessionManager::SessionManager(void) :
no_of_imapconnections_(-1),
no_of_smtpconnections_(-1),
no_of_pop3connections_(-1)
no_of_imapconnections_(0),
no_of_smtpconnections_(0),
no_of_pop3connections_(0)
{

}
Expand All @@ -41,98 +41,106 @@ namespace HM
}

bool
SessionManager::GetAllow(SessionType session_type, std::shared_ptr<SecurityRange> security_range)
SessionManager::CreateSession(SessionType session_type, std::shared_ptr<SecurityRange> security_range)
{
// Check that client isn't blocked by IP range.
switch (session_type)
{
case STSMTP:
if (!security_range->GetAllowSMTP())
if (security_range == nullptr || !security_range->GetAllowSMTP())
return false;
break;
case STPOP3:
if (!security_range->GetAllowPOP3())
if (security_range == nullptr || !security_range->GetAllowPOP3())
return false;
break;
case STIMAP:
if (!security_range->GetAllowIMAP())
if (security_range == nullptr || !security_range->GetAllowIMAP())
return false;
break;
}

int current_connections = GetNumberOfConnections(session_type);


// Check max per protocol
int max_connections = 0;
switch (session_type)
{
case STSMTP:
{
int connection_count = no_of_smtpconnections_.fetch_add(1) + 1;

max_connections = Configuration::Instance()->GetSMTPConfiguration()->GetMaxSMTPConnections();
if (max_connections > 0 && current_connections > max_connections)
if (max_connections > 0 && connection_count > max_connections)
{
no_of_smtpconnections_--;
return false;
}

break;
}
case STPOP3:
{
int connection_count = no_of_pop3connections_.fetch_add(1) + 1;

max_connections = Configuration::Instance()->GetPOP3Configuration()->GetMaxPOP3Connections();
if (max_connections > 0 && current_connections > max_connections)
if (max_connections > 0 && connection_count > max_connections)
{
no_of_pop3connections_--;
return false;
}

break;
}
case STIMAP:
{
int connection_count = no_of_imapconnections_.fetch_add(1) + 1;

max_connections = Configuration::Instance()->GetIMAPConfiguration()->GetMaxIMAPConnections();
if (max_connections > 0 && current_connections > max_connections)
if (max_connections > 0 && connection_count > max_connections)
{
no_of_imapconnections_--;
return false;
}

break;
}
}

return true;
}

void
SessionManager::OnCreate(SessionType t)
void
SessionManager::OnSessionEnded(SessionType st)
{
switch (t)
switch (st)
{
case STSMTP:
{
no_of_smtpconnections_++;
break;
}
no_of_smtpconnections_--;
break;
case STPOP3:
{
no_of_pop3connections_++;
break;
}
no_of_pop3connections_--;
break;
case STIMAP:
{
no_of_imapconnections_++;
break;
}
no_of_imapconnections_--;
break;
}
}


void
SessionManager::OnDestroy(SessionType st)
{
#ifdef DEBUG
switch (st)
{
case STSMTP:
no_of_smtpconnections_--;
if (no_of_smtpconnections_ < 0)
throw std::logic_error("Negative session count.");
break;
case STPOP3:
no_of_pop3connections_--;
if (no_of_pop3connections_ < 0)
throw std::logic_error("Negative session count.");
break;
case STIMAP:
no_of_imapconnections_--;
if (no_of_imapconnections_ < 0)
throw std::logic_error("Negative session count.");
break;
}
#endif

}


Expand Down
5 changes: 2 additions & 3 deletions hmailserver/source/Server/Common/Application/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ namespace HM

int Count();

bool GetAllow(SessionType t, std::shared_ptr<SecurityRange> security_range);
void OnCreate(SessionType t);
void OnDestroy(SessionType st);
bool CreateSession(SessionType t, std::shared_ptr<SecurityRange> security_range);
void OnSessionEnded(SessionType st);

int GetNumberOfConnections(SessionType st);
// Returns the number of connections for a specific connection timeout
Expand Down
2 changes: 1 addition & 1 deletion hmailserver/source/Server/Common/BO/MessageData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ namespace HM
{
const HM::String directoryName = HM::FileUtilities::GetFilePath(fileName);
if (!HM::FileUtilities::Exists(directoryName))
HM::FileUtilities::CreateDirectoryRecursive(directoryName);
HM::FileUtilities::CreateDirectory(directoryName);

bool result = mime_mail_->SaveAllToFile(fileName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ namespace HM
// We start by checking if it already exists. If not, attempt to create. We used
// to create each folder before. Checking first will save some disk access.
if (!FileUtilities::Exists(destinationPath))
FileUtilities::CreateDirectoryRecursive(destinationPath);
FileUtilities::CreateDirectory(destinationPath);

// Move the old file to the new path.
if (!FileUtilities::Move(sourceLocation, destinationFileName))
Expand All @@ -734,7 +734,7 @@ namespace HM
// We start by checking if it already exists. If not, attempt to create. We used
// to create each folder before. Checking first will save some disk access.
if (!FileUtilities::Exists(destinationPath))
FileUtilities::CreateDirectoryRecursive(destinationPath);
FileUtilities::CreateDirectory(destinationPath);

// Move the old file to the new path.
if (!FileUtilities::Move(sourceLocation, destinationFileName))
Expand All @@ -755,7 +755,7 @@ namespace HM
// in which the message should be put. If the dir doesn't exist, we'll
// have slight problems creating a file in it.
String sPath = FileUtilities::GetFilePath(sFileName);
FileUtilities::CreateDirectoryRecursive(sPath);
FileUtilities::CreateDirectory(sPath);


// The file does not exists. May have been deleted
Expand Down
5 changes: 3 additions & 2 deletions hmailserver/source/Server/Common/TCPIP/SocketConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ namespace HM

enum ConnectionState
{
StateDisconnected = 0,
StatePendingConnect = 0,
StateConnected = 1,
StatePendingDisconnect = 2
StatePendingDisconnect = 2,
StateDisconnected = 3
};

enum SslTlsVersion
Expand Down
2 changes: 1 addition & 1 deletion hmailserver/source/Server/Common/TCPIP/TCPConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace HM
expected_remote_hostname_(expected_remote_hostname),
is_client_(false),
timeout_(0),
connection_state_(StateDisconnected)
connection_state_(StatePendingConnect)
{
session_id_ = Application::Instance()->GetUniqueID();

Expand Down
2 changes: 2 additions & 0 deletions hmailserver/source/Server/Common/TCPIP/TCPConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace HM

protected:

ConnectionState GetConnectionState() { return connection_state_; }
int GetSessionID();

int GetBufferSize() {return BufferSize; }
Expand All @@ -92,6 +93,7 @@ namespace HM
virtual void ParseData(std::shared_ptr<ByteBuffer> pByteBuffer) = 0;

AnsiString GetSslTlsCipher();

private:

void ThrowIfNotConnected_();
Expand Down
Loading

0 comments on commit 85d5576

Please sign in to comment.