Bug 1288308 - Part 0: add Named Pipe type on Windows platform; r=bagder

MozReview-Commit-ID: It2l5BJuHiS
This commit is contained in:
Liang-Heng Chen 2016-09-01 15:48:39 +08:00
Родитель fee5f1f348
Коммит 77847254f2
8 изменённых файлов: 55 добавлений и 31 удалений

Просмотреть файл

@ -301,6 +301,7 @@ LOCAL_INCLUDES += [
'/docshell/base',
'/dom/base',
'/netwerk/protocol/http',
'/netwerk/socket',
'/security/pkix/include'
]

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsThreadUtils.h"
#include "nsSOCKSIOLayer.h"
#include "nsString.h"
#include "nsNetUtil.h"
#include "nsNetCID.h"
@ -387,16 +388,6 @@ proxy_GetBoolPref(nsIPrefBranch *aPrefBranch,
aResult = temp;
}
static inline bool
IsHostDomainSocket(const nsACString& aHost)
{
#ifdef XP_UNIX
return Substring(aHost, 0, 5) == "file:";
#else
return false;
#endif // XP_UNIX
}
//----------------------------------------------------------------------------
static const int32_t PROXYCONFIG_DIRECT4X = 3;
@ -1862,7 +1853,7 @@ nsProtocolProxyService::Resolve_Internal(nsIChannel *channel,
if ((flags & RESOLVE_PREFER_SOCKS_PROXY) &&
!mSOCKSProxyTarget.IsEmpty() &&
(IsHostDomainSocket(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
(IsHostLocalTarget(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
host = &mSOCKSProxyTarget;
if (mSOCKSProxyVersion == 4)
type = kProxyType_SOCKS4;
@ -1900,7 +1891,7 @@ nsProtocolProxyService::Resolve_Internal(nsIChannel *channel,
port = mFTPProxyPort;
}
else if (!mSOCKSProxyTarget.IsEmpty() &&
(IsHostDomainSocket(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
(IsHostLocalTarget(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
host = &mSOCKSProxyTarget;
if (mSOCKSProxyVersion == 4)
type = kProxyType_SOCKS4;

Просмотреть файл

@ -382,7 +382,8 @@ protected:
nsCString mHTTPSProxyHost;
int32_t mHTTPSProxyPort;
// mSOCKSProxyTarget could be a host or a domain socket path.
// mSOCKSProxyTarget could be a host, a domain socket path,
// or a named-pipe name.
nsCString mSOCKSProxyTarget;
int32_t mSOCKSProxyPort;
int32_t mSOCKSProxyVersion;

Просмотреть файл

@ -92,6 +92,11 @@ void NetAddrToPRNetAddr(const NetAddr *addr, PRNetAddr *prAddr)
prAddr->local.family = PR_AF_LOCAL;
memcpy(prAddr->local.path, addr->local.path, sizeof(addr->local.path));
}
#elif defined(XP_WIN)
else if (addr->raw.family == AF_LOCAL) {
prAddr->local.family = PR_AF_LOCAL;
memcpy(prAddr->local.path, addr->local.path, sizeof(addr->local.path));
}
#endif
}

Просмотреть файл

@ -22,6 +22,10 @@
#include "winsock2.h"
#endif
#ifndef AF_LOCAL
#define AF_LOCAL 1 // used for named pipe
#endif
#define IPv6ADDR_IS_LOOPBACK(a) \
(((a)->u32[0] == 0) && \
((a)->u32[1] == 0) && \
@ -103,8 +107,9 @@ union NetAddr {
IPv6Addr ip; /* the actual 128 bits of address */
uint32_t scope_id; /* set of interfaces for a scope */
} inet6;
#if defined(XP_UNIX)
struct { /* Unix domain socket address */
#if defined(XP_UNIX) || defined(XP_WIN)
struct { /* Unix domain socket or
Windows Named Pipes address */
uint16_t family; /* address family (AF_UNIX) */
char path[104]; /* null-terminated pathname */
} local;

Просмотреть файл

@ -114,19 +114,15 @@ private:
PRStatus ReadFromSocket(PRFileDesc *fd);
PRStatus WriteToSocket(PRFileDesc *fd);
bool IsHostDomainSocket()
bool IsLocalProxy()
{
#ifdef XP_UNIX
nsAutoCString proxyHost;
mProxy->GetHost(proxyHost);
return Substring(proxyHost, 0, 5) == "file:";
#else
return false;
#endif // XP_UNIX
return IsHostLocalTarget(proxyHost);
}
nsresult SetDomainSocketPath(const nsACString& aDomainSocketPath,
NetAddr* aProxyAddr)
nsresult SetLocalProxyPath(const nsACString& aLocalProxyPath,
NetAddr* aProxyAddr)
{
#ifdef XP_UNIX
nsresult rv;
@ -145,7 +141,7 @@ private:
}
nsCOMPtr<nsIFile> socketFile;
rv = fileHandler->GetFileFromURLSpec(aDomainSocketPath,
rv = fileHandler->GetFileFromURLSpec(aLocalProxyPath,
getter_AddRefs(socketFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -164,10 +160,21 @@ private:
aProxyAddr->raw.family = AF_UNIX;
strcpy(aProxyAddr->local.path, path.get());
return NS_OK;
#elif defined(XP_WIN)
MOZ_ASSERT(aProxyAddr);
if (sizeof(aProxyAddr->local.path) <= aLocalProxyPath.Length()) {
NS_WARNING("pipe path too long.");
return NS_ERROR_FAILURE;
}
aProxyAddr->raw.family = AF_LOCAL;
strcpy(aProxyAddr->local.path, PromiseFlatCString(aLocalProxyPath).get());
return NS_OK;
#else
mozilla::Unused << aLocalProxyPath;
mozilla::Unused << aProxyAddr;
mozilla::Unused << aDomainSocketPath;
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
@ -489,12 +496,12 @@ nsSOCKSSocketInfo::ConnectToProxy(PRFileDesc *fd)
int32_t addresses = 0;
do {
if (IsHostDomainSocket()) {
rv = SetDomainSocketPath(proxyHost, &mInternalProxyAddr);
if (IsLocalProxy()) {
rv = SetLocalProxyPath(proxyHost, &mInternalProxyAddr);
if (NS_FAILED(rv)) {
LOGERROR(("socks: unable to connect to SOCKS proxy, %s",
proxyHost.get()));
return PR_FAILURE;
return PR_FAILURE;
}
} else {
if (addresses++) {
@ -529,7 +536,7 @@ nsSOCKSSocketInfo::ConnectToProxy(PRFileDesc *fd)
if (c == PR_WOULD_BLOCK_ERROR || c == PR_IN_PROGRESS_ERROR) {
mState = SOCKS_CONNECTING_TO_PROXY;
return status;
} else if (IsHostDomainSocket()) {
} else if (IsLocalProxy()) {
LOGERROR(("socks: connect to domain socket failed (%d)", c));
PR_SetError(PR_CONNECT_REFUSED_ERROR, 0);
mState = SOCKS_FAILED;
@ -1049,7 +1056,7 @@ nsSOCKSSocketInfo::DoHandshake(PRFileDesc *fd, int16_t oflags)
switch (mState) {
case SOCKS_INITIAL:
if (IsHostDomainSocket()) {
if (IsLocalProxy()) {
mState = SOCKS_DNS_COMPLETE;
mLookupStatus = NS_OK;
return ConnectToProxy(fd);
@ -1535,3 +1542,15 @@ nsSOCKSIOLayerAddToSocket(int32_t family,
NS_ADDREF(*info);
return NS_OK;
}
bool
IsHostLocalTarget(const nsACString& aHost)
{
#if defined(XP_UNIX)
return StringBeginsWith(aHost, NS_LITERAL_CSTRING("file:"));
#elif defined(XP_WIN)
return StringBeginsWith(aHost, NS_LITERAL_CSTRING("\\\\.\\pipe\\"));
#else
return false;
#endif // XP_UNIX
}

Просмотреть файл

@ -20,4 +20,6 @@ nsresult nsSOCKSIOLayerAddToSocket(int32_t family,
PRFileDesc *fd,
nsISupports **info);
bool IsHostLocalTarget(const nsACString& aHost);
#endif /* nsSOCKSIOLayer_h__ */

Просмотреть файл

@ -168,7 +168,7 @@ union PRNetAddr {
PRIPv6Addr ip; /* the actual 128 bits of address */
PRUint32 scope_id; /* set of interfaces for a scope */
} ipv6;
#if defined(XP_UNIX) || defined(XP_OS2)
#if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_WIN)
struct { /* Unix domain socket address */
PRUint16 family; /* address family (AF_UNIX) */
#ifdef XP_OS2