Skip to content

Commit

Permalink
feature: ip:port not supported #241
Browse files Browse the repository at this point in the history
  • Loading branch information
chcg committed Sep 25, 2021
1 parent e81d007 commit 81e2fec
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/FTPCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const char * FTPCache::CacheElem = "Cache";
const int PathCacheSize = MAX_PATH+10; //paths generally do not exceed MAX_PATH, but if it happens often buffer reallocation may need some profiling (e.g. set ceiling instead of just allocating)

FTPCache::FTPCache() :
m_cacheParent(NULL)
m_cacheParent(NULL),
m_activePort(0)
{
m_activeHost = SU::DupString(TEXT(""));
m_activeUser = SU::DupString(TEXT(""));
Expand All @@ -42,12 +43,13 @@ int FTPCache::SetCacheParent(FTPCache * cacheParent) {
return 0;
}

int FTPCache::SetEnvironment(const char * host, const char * user) {
int FTPCache::SetEnvironment(const char * host, const char * user, int port) {
SU::FreeTChar(m_activeHost);
SU::FreeTChar(m_activeUser);

m_activeHost = SU::Utf8ToTChar(host);
m_activeUser = SU::Utf8ToTChar(user);
m_activePort = port;

ExpandPaths();

Expand Down Expand Up @@ -331,6 +333,8 @@ TCHAR* FTPCache::ExpandPath(const TCHAR * path) {
}
replacestring = SU::ReplaceString(replacestring, TEXT("%USERNAME%"), m_activeUser);
replacestring = SU::ReplaceString(replacestring, TEXT("%HOSTNAME%"), m_activeHost);
tstring port = std::to_wstring(m_activePort);
replacestring = SU::ReplaceString(replacestring, TEXT("%PORT%"), port);

TCHAR * expanded = new TCHAR[MAX_PATH];
BOOL res = PathSearchAndQualify(replacestring.c_str(), expanded, MAX_PATH);
Expand Down
3 changes: 2 additions & 1 deletion src/FTPCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FTPCache {
virtual ~FTPCache();

virtual int SetCacheParent(FTPCache * m_cacheParent);
virtual int SetEnvironment(const char * host, const char * user);
virtual int SetEnvironment(const char * host, const char * user, int port);

virtual const PathMap & GetPathMap(int i) const;
virtual int GetPathMapCount() const;
Expand Down Expand Up @@ -67,6 +67,7 @@ class FTPCache {

TCHAR* m_activeHost;
TCHAR* m_activeUser;
int m_activePort;
};

#endif //FTPCACHE_H
9 changes: 5 additions & 4 deletions src/FTPProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FTPProfile::FTPProfile(const TCHAR * name) :
m_keyFile = SU::DupString(TEXT(""));
m_passphrase = SU::strdup("");

m_cache->SetEnvironment(m_hostname, m_username);
m_cache->SetEnvironment(m_hostname, m_username, m_port);
}

FTPProfile::FTPProfile(const TCHAR * name, const FTPProfile* other) :
Expand Down Expand Up @@ -108,7 +108,7 @@ FTPProfile::FTPProfile(const TCHAR * name, const FTPProfile* other) :
m_keyFile = SU::DupString(other->m_keyFile);
m_passphrase = SU::strdup(other->m_passphrase);

m_cache->SetEnvironment(m_hostname, m_username);
m_cache->SetEnvironment(m_hostname, m_username, m_port);

for(int i = 0; i < other->m_cache->GetPathMapCount(); i++) {
PathMap map;
Expand Down Expand Up @@ -262,7 +262,7 @@ int FTPProfile::SetParent(const TCHAR * parent) {
int FTPProfile::SetHostname(const char * hostname) {
SU::free(m_hostname);
m_hostname = SU::strdup(hostname);
m_cache->SetEnvironment(m_hostname, m_username);
m_cache->SetEnvironment(m_hostname, m_username, m_port);
return 0;
}

Expand All @@ -274,6 +274,7 @@ int FTPProfile::SetPort(int port) {
if (port <= 0 || port >= 65536)
return -1;
m_port = port;
m_cache->SetEnvironment(m_hostname, m_username, m_port);
return 0;
}

Expand All @@ -284,7 +285,7 @@ const char* FTPProfile::GetUsername() const {
int FTPProfile::SetUsername(const char * username) {
SU::free(m_username);
m_username = SU::strdup(username);
m_cache->SetEnvironment(m_hostname, m_username);
m_cache->SetEnvironment(m_hostname, m_username, m_port);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/FTPSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int FTPSession::StartSession(FTPProfile * sessionProfile) {
m_currentProfile = sessionProfile;
m_currentProfile->AddRef();

m_ftpSettings->GetGlobalCache()->SetEnvironment(m_currentProfile->GetHostname(), m_currentProfile->GetUsername());
m_ftpSettings->GetGlobalCache()->SetEnvironment(m_currentProfile->GetHostname(), m_currentProfile->GetUsername(), m_currentProfile->GetPort());

m_mainWrapper = m_currentProfile->CreateWrapper();
if (m_mainWrapper == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/FTPSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const TCHAR* FTPSettings::GetGlobalCachePath() const {

int FTPSettings::SetGlobalCachePath(const TCHAR * path) {
if (!path || lstrlen(path) < 4) { //must at least have a drive designator or network name
path = TEXT("%CONFIGDIR%\\Cache\\%USERNAME%@%HOSTNAME%");
path = TEXT("%CONFIGDIR%\\Cache\\%USERNAME%@%HOSTNAME%\\%PORT%");
}

PathMap globalPathmap;
Expand Down

0 comments on commit 81e2fec

Please sign in to comment.