Skip to content

Commit

Permalink
Bug 1479: Handle dav:// URL
Browse files Browse the repository at this point in the history
https://winscp.net/tracker/1479

Source commit: c2dd8d68e98b48354a9a60c33b35a1ab7e35efb1
  • Loading branch information
martinprikryl committed Jan 27, 2018
1 parent 99a44f2 commit b4df717
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions dotnet/Session.cs
Expand Up @@ -1390,11 +1390,11 @@ private void SessionOptionsToUrlAndSwitches(SessionOptions sessionOptions, bool
case Protocol.Webdav:
if (!sessionOptions.WebdavSecure)
{
head = "http://";
head = "dav://";
}
else
{
head = "https://";
head = "davs://";
}
break;

Expand Down
6 changes: 4 additions & 2 deletions dotnet/SessionOptions.cs
Expand Up @@ -246,11 +246,13 @@ private bool ParseProtocol(string protocol)
Protocol = Protocol.Ftp;
FtpSecure = FtpSecure.Explicit;
}
else if (protocol.Equals("http", StringComparison.OrdinalIgnoreCase))
else if (protocol.Equals("dav", StringComparison.OrdinalIgnoreCase) ||
protocol.Equals("http", StringComparison.OrdinalIgnoreCase))
{
Protocol = Protocol.Webdav;
}
else if (protocol.Equals("https", StringComparison.OrdinalIgnoreCase))
else if (protocol.Equals("davs", StringComparison.OrdinalIgnoreCase) ||
protocol.Equals("https", StringComparison.OrdinalIgnoreCase))
{
Protocol = Protocol.Webdav;
WebdavSecure = true;
Expand Down
2 changes: 1 addition & 1 deletion source/core/NeonIntf.cpp
Expand Up @@ -32,7 +32,7 @@ void NeonParseUrl(const UnicodeString & Url, ne_uri & uri)
//---------------------------------------------------------------------------
bool IsTlsUri(const ne_uri & uri)
{
return SameText(StrFromNeon(uri.scheme), WebDAVSProtocol);
return SameText(StrFromNeon(uri.scheme), HttpsProtocol);
}
//---------------------------------------------------------------------------
struct TProxyAuthData
Expand Down
8 changes: 6 additions & 2 deletions source/core/SessionData.cpp
Expand Up @@ -51,6 +51,8 @@ const UnicodeString ScpProtocol(L"scp");
const UnicodeString FtpProtocol(L"ftp");
const UnicodeString FtpsProtocol(L"ftps");
const UnicodeString FtpesProtocol(L"ftpes");
const UnicodeString WebDAVProtocol(L"dav");
const UnicodeString WebDAVSProtocol(L"davs");
const UnicodeString SshProtocol(L"ssh");
const UnicodeString WinSCPProtocolPrefix(L"winscp-");
const wchar_t UrlParamSeparator = L';';
Expand Down Expand Up @@ -1623,15 +1625,17 @@ bool __fastcall TSessionData::ParseUrl(UnicodeString Url, TOptions * Options,
MoveStr(Url, MaskedUrl, ProtocolLen);
ProtocolDefined = true;
}
else if (IsProtocolUrl(Url, WebDAVProtocol, ProtocolLen))
else if (IsProtocolUrl(Url, WebDAVProtocol, ProtocolLen) ||
IsProtocolUrl(Url, HttpProtocol, ProtocolLen))
{
AFSProtocol = fsWebDAV;
AFtps = ftpsNone;
APortNumber = HTTPPortNumber;
MoveStr(Url, MaskedUrl, ProtocolLen);
ProtocolDefined = true;
}
else if (IsProtocolUrl(Url, WebDAVSProtocol, ProtocolLen))
else if (IsProtocolUrl(Url, WebDAVSProtocol, ProtocolLen) ||
IsProtocolUrl(Url, HttpsProtocol, ProtocolLen))
{
AFSProtocol = fsWebDAV;
AFtps = ftpsImplicit;
Expand Down
4 changes: 2 additions & 2 deletions source/core/SessionData.h
Expand Up @@ -72,8 +72,8 @@ extern const UnicodeString ScpProtocol;
extern const UnicodeString FtpProtocol;
extern const UnicodeString FtpsProtocol;
extern const UnicodeString FtpesProtocol;
#define WebDAVProtocol HttpProtocol
#define WebDAVSProtocol HttpsProtocol
extern const UnicodeString WebDAVProtocol;
extern const UnicodeString WebDAVSProtocol;
extern const UnicodeString SshProtocol;
extern const UnicodeString WinSCPProtocolPrefix;
extern const wchar_t UrlParamSeparator;
Expand Down
2 changes: 1 addition & 1 deletion source/core/WebDAVFileSystem.cpp
Expand Up @@ -293,7 +293,7 @@ void __fastcall TWebDAVFileSystem::Open()

UnicodeString HostName = Data->HostNameExpanded;
size_t Port = Data->PortNumber;
UnicodeString ProtocolName = (FTerminal->SessionData->Ftps == ftpsNone) ? WebDAVProtocol : WebDAVSProtocol;
UnicodeString ProtocolName = (FTerminal->SessionData->Ftps == ftpsNone) ? HttpProtocol : HttpsProtocol;
UnicodeString Path = Data->RemoteDirectory;
// PathToNeon is not used as we cannot call AbsolutePath here
UnicodeString EscapedPath = StrFromNeon(PathEscape(StrToNeon(Path)).c_str());
Expand Down
2 changes: 1 addition & 1 deletion source/resource/TextsCore2.rc
Expand Up @@ -61,7 +61,7 @@ BEGIN
" bye\n"
SCRIPT_OPEN_HELP9,
"open <site>\n"
"open sftp|scp|ftp[es]|http[s] :// [ <user> [ :password ] @ ] <host> [ :<port> ]\n"
"open sftp|scp|ftp[es]|dav[s] :// [ <user> [ :password ] @ ] <host> [ :<port> ]\n"
" Establishes connection to given host. Use either name of the site or\n"
" specify host, username, port and protocol directly.\n"
"switches:\n"
Expand Down
2 changes: 1 addition & 1 deletion source/windows/ConsoleRunner.cpp
Expand Up @@ -2104,7 +2104,7 @@ void __fastcall Usage(TConsole * Console)
if (!Console->CommandLineOnly())
{
PrintUsageSyntax(Console, L"site|workspace|folder");
PrintUsageSyntax(Console, L"(sftp|scp|ftp[es]|http[s])://[user[:password]@]host[:port][/path/[file]]");
PrintUsageSyntax(Console, L"(sftp|scp|ftp[es]|dav[s])://[user[:password]@]host[:port][/path/[file]]");
PrintUsageSyntax(Console, FORMAT(L"[mysession] /%s=<name>", (LowerCase(SESSIONNAME_SWICH))));
PrintUsageSyntax(Console, L"[mysession] /newinstance");
PrintUsageSyntax(Console, L"[mysession] /edit <path>");
Expand Down
19 changes: 13 additions & 6 deletions source/windows/Setup.cpp
Expand Up @@ -465,12 +465,16 @@ static void __fastcall RegisterAsNonBrowserUrlHandler(const UnicodeString & Pref
{
RegisterAsUrlHandler(Prefix + SftpProtocol.UpperCase());
RegisterAsUrlHandler(Prefix + ScpProtocol.UpperCase());
RegisterAsUrlHandler(Prefix + WebDAVProtocol.UpperCase());
RegisterAsUrlHandler(Prefix + WebDAVSProtocol.UpperCase());
}
//---------------------------------------------------------------------------
static void __fastcall UnregisterAsUrlHandlers(const UnicodeString & Prefix, bool UnregisterProtocol)
{
UnregisterAsUrlHandler(Prefix + SftpProtocol, UnregisterProtocol);
UnregisterAsUrlHandler(Prefix + ScpProtocol, UnregisterProtocol);
UnregisterAsUrlHandler(Prefix + WebDAVProtocol, UnregisterProtocol);
UnregisterAsUrlHandler(Prefix + WebDAVSProtocol, UnregisterProtocol);
}
//---------------------------------------------------------------------------
static const UnicodeString GenericUrlHandler(L"WinSCP.Url");
Expand Down Expand Up @@ -574,7 +578,9 @@ static void __fastcall RegisterProtocolsForDefaultPrograms(HKEY RootKey)
RegisterProtocolForDefaultPrograms(RootKey, SftpProtocol);
RegisterProtocolForDefaultPrograms(RootKey, ScpProtocol);
RegisterProtocolForDefaultPrograms(RootKey, SshProtocol);
// deliberately not including WebDAV/http,
RegisterProtocolForDefaultPrograms(RootKey, WebDAVProtocol);
RegisterProtocolForDefaultPrograms(RootKey, WebDAVSProtocol);
// deliberately not including http,
// it's unlikely that anyone would like to change http handler
// to non-browser application
}
Expand All @@ -586,7 +592,8 @@ static void __fastcall UnregisterProtocolsForDefaultPrograms(HKEY RootKey, bool
UnregisterProtocolForDefaultPrograms(RootKey, FtpesProtocol, ForceHandlerUnregistration);
UnregisterProtocolForDefaultPrograms(RootKey, SftpProtocol, ForceHandlerUnregistration);
UnregisterProtocolForDefaultPrograms(RootKey, ScpProtocol, ForceHandlerUnregistration);
UnregisterProtocolForDefaultPrograms(RootKey, SshProtocol, ForceHandlerUnregistration);
UnregisterProtocolForDefaultPrograms(RootKey, WebDAVProtocol, ForceHandlerUnregistration);
UnregisterProtocolForDefaultPrograms(RootKey, WebDAVSProtocol, ForceHandlerUnregistration);

// we should not really need the "force" flag here, but why not
UnregisterAsUrlHandler(RootKey, GenericUrlHandler, true, true);
Expand Down Expand Up @@ -635,8 +642,8 @@ void __fastcall RegisterForDefaultProtocols()
RegisterAsUrlHandler(WinSCPProtocolPrefix + FtpProtocol.UpperCase());
RegisterAsUrlHandler(WinSCPProtocolPrefix + FtpsProtocol.UpperCase());
RegisterAsUrlHandler(WinSCPProtocolPrefix + FtpesProtocol.UpperCase());
RegisterAsUrlHandler(WinSCPProtocolPrefix + WebDAVProtocol.UpperCase());
RegisterAsUrlHandler(WinSCPProtocolPrefix + WebDAVSProtocol.UpperCase());
RegisterAsUrlHandler(WinSCPProtocolPrefix + HttpProtocol.UpperCase());
RegisterAsUrlHandler(WinSCPProtocolPrefix + HttpsProtocol.UpperCase());
RegisterAsUrlHandler(WinSCPProtocolPrefix + SshProtocol.UpperCase());

NotifyChangedAssociations();
Expand All @@ -649,8 +656,8 @@ void __fastcall UnregisterForProtocols()
UnregisterAsUrlHandler(WinSCPProtocolPrefix + FtpProtocol.UpperCase(), true);
UnregisterAsUrlHandler(WinSCPProtocolPrefix + FtpsProtocol.UpperCase(), true);
UnregisterAsUrlHandler(WinSCPProtocolPrefix + FtpesProtocol.UpperCase(), true);
UnregisterAsUrlHandler(WinSCPProtocolPrefix + WebDAVProtocol.UpperCase(), true);
UnregisterAsUrlHandler(WinSCPProtocolPrefix + WebDAVSProtocol.UpperCase(), true);
UnregisterAsUrlHandler(WinSCPProtocolPrefix + HttpProtocol.UpperCase(), true);
UnregisterAsUrlHandler(WinSCPProtocolPrefix + HttpsProtocol.UpperCase(), true);
UnregisterAsUrlHandler(WinSCPProtocolPrefix + SshProtocol.UpperCase(), true);

UnregisterProtocolsForDefaultPrograms(HKEY_CURRENT_USER, false);
Expand Down

0 comments on commit b4df717

Please sign in to comment.