зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1288308 - Part 0: add Named Pipe type on Windows platform; r=bagder
MozReview-Commit-ID: It2l5BJuHiS
This commit is contained in:
Родитель
fee5f1f348
Коммит
77847254f2
|
@ -301,6 +301,7 @@ LOCAL_INCLUDES += [
|
||||||
'/docshell/base',
|
'/docshell/base',
|
||||||
'/dom/base',
|
'/dom/base',
|
||||||
'/netwerk/protocol/http',
|
'/netwerk/protocol/http',
|
||||||
|
'/netwerk/socket',
|
||||||
'/security/pkix/include'
|
'/security/pkix/include'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "nsIPrefService.h"
|
#include "nsIPrefService.h"
|
||||||
#include "nsIPrefBranch.h"
|
#include "nsIPrefBranch.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
#include "nsSOCKSIOLayer.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsNetUtil.h"
|
#include "nsNetUtil.h"
|
||||||
#include "nsNetCID.h"
|
#include "nsNetCID.h"
|
||||||
|
@ -387,16 +388,6 @@ proxy_GetBoolPref(nsIPrefBranch *aPrefBranch,
|
||||||
aResult = temp;
|
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;
|
static const int32_t PROXYCONFIG_DIRECT4X = 3;
|
||||||
|
@ -1862,7 +1853,7 @@ nsProtocolProxyService::Resolve_Internal(nsIChannel *channel,
|
||||||
|
|
||||||
if ((flags & RESOLVE_PREFER_SOCKS_PROXY) &&
|
if ((flags & RESOLVE_PREFER_SOCKS_PROXY) &&
|
||||||
!mSOCKSProxyTarget.IsEmpty() &&
|
!mSOCKSProxyTarget.IsEmpty() &&
|
||||||
(IsHostDomainSocket(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
|
(IsHostLocalTarget(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
|
||||||
host = &mSOCKSProxyTarget;
|
host = &mSOCKSProxyTarget;
|
||||||
if (mSOCKSProxyVersion == 4)
|
if (mSOCKSProxyVersion == 4)
|
||||||
type = kProxyType_SOCKS4;
|
type = kProxyType_SOCKS4;
|
||||||
|
@ -1900,7 +1891,7 @@ nsProtocolProxyService::Resolve_Internal(nsIChannel *channel,
|
||||||
port = mFTPProxyPort;
|
port = mFTPProxyPort;
|
||||||
}
|
}
|
||||||
else if (!mSOCKSProxyTarget.IsEmpty() &&
|
else if (!mSOCKSProxyTarget.IsEmpty() &&
|
||||||
(IsHostDomainSocket(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
|
(IsHostLocalTarget(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
|
||||||
host = &mSOCKSProxyTarget;
|
host = &mSOCKSProxyTarget;
|
||||||
if (mSOCKSProxyVersion == 4)
|
if (mSOCKSProxyVersion == 4)
|
||||||
type = kProxyType_SOCKS4;
|
type = kProxyType_SOCKS4;
|
||||||
|
|
|
@ -382,7 +382,8 @@ protected:
|
||||||
nsCString mHTTPSProxyHost;
|
nsCString mHTTPSProxyHost;
|
||||||
int32_t mHTTPSProxyPort;
|
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;
|
nsCString mSOCKSProxyTarget;
|
||||||
int32_t mSOCKSProxyPort;
|
int32_t mSOCKSProxyPort;
|
||||||
int32_t mSOCKSProxyVersion;
|
int32_t mSOCKSProxyVersion;
|
||||||
|
|
|
@ -92,6 +92,11 @@ void NetAddrToPRNetAddr(const NetAddr *addr, PRNetAddr *prAddr)
|
||||||
prAddr->local.family = PR_AF_LOCAL;
|
prAddr->local.family = PR_AF_LOCAL;
|
||||||
memcpy(prAddr->local.path, addr->local.path, sizeof(addr->local.path));
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,10 @@
|
||||||
#include "winsock2.h"
|
#include "winsock2.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef AF_LOCAL
|
||||||
|
#define AF_LOCAL 1 // used for named pipe
|
||||||
|
#endif
|
||||||
|
|
||||||
#define IPv6ADDR_IS_LOOPBACK(a) \
|
#define IPv6ADDR_IS_LOOPBACK(a) \
|
||||||
(((a)->u32[0] == 0) && \
|
(((a)->u32[0] == 0) && \
|
||||||
((a)->u32[1] == 0) && \
|
((a)->u32[1] == 0) && \
|
||||||
|
@ -103,8 +107,9 @@ union NetAddr {
|
||||||
IPv6Addr ip; /* the actual 128 bits of address */
|
IPv6Addr ip; /* the actual 128 bits of address */
|
||||||
uint32_t scope_id; /* set of interfaces for a scope */
|
uint32_t scope_id; /* set of interfaces for a scope */
|
||||||
} inet6;
|
} inet6;
|
||||||
#if defined(XP_UNIX)
|
#if defined(XP_UNIX) || defined(XP_WIN)
|
||||||
struct { /* Unix domain socket address */
|
struct { /* Unix domain socket or
|
||||||
|
Windows Named Pipes address */
|
||||||
uint16_t family; /* address family (AF_UNIX) */
|
uint16_t family; /* address family (AF_UNIX) */
|
||||||
char path[104]; /* null-terminated pathname */
|
char path[104]; /* null-terminated pathname */
|
||||||
} local;
|
} local;
|
||||||
|
|
|
@ -114,19 +114,15 @@ private:
|
||||||
PRStatus ReadFromSocket(PRFileDesc *fd);
|
PRStatus ReadFromSocket(PRFileDesc *fd);
|
||||||
PRStatus WriteToSocket(PRFileDesc *fd);
|
PRStatus WriteToSocket(PRFileDesc *fd);
|
||||||
|
|
||||||
bool IsHostDomainSocket()
|
bool IsLocalProxy()
|
||||||
{
|
{
|
||||||
#ifdef XP_UNIX
|
|
||||||
nsAutoCString proxyHost;
|
nsAutoCString proxyHost;
|
||||||
mProxy->GetHost(proxyHost);
|
mProxy->GetHost(proxyHost);
|
||||||
return Substring(proxyHost, 0, 5) == "file:";
|
return IsHostLocalTarget(proxyHost);
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif // XP_UNIX
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult SetDomainSocketPath(const nsACString& aDomainSocketPath,
|
nsresult SetLocalProxyPath(const nsACString& aLocalProxyPath,
|
||||||
NetAddr* aProxyAddr)
|
NetAddr* aProxyAddr)
|
||||||
{
|
{
|
||||||
#ifdef XP_UNIX
|
#ifdef XP_UNIX
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
@ -145,7 +141,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIFile> socketFile;
|
nsCOMPtr<nsIFile> socketFile;
|
||||||
rv = fileHandler->GetFileFromURLSpec(aDomainSocketPath,
|
rv = fileHandler->GetFileFromURLSpec(aLocalProxyPath,
|
||||||
getter_AddRefs(socketFile));
|
getter_AddRefs(socketFile));
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -164,10 +160,21 @@ private:
|
||||||
aProxyAddr->raw.family = AF_UNIX;
|
aProxyAddr->raw.family = AF_UNIX;
|
||||||
strcpy(aProxyAddr->local.path, path.get());
|
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;
|
return NS_OK;
|
||||||
#else
|
#else
|
||||||
|
mozilla::Unused << aLocalProxyPath;
|
||||||
mozilla::Unused << aProxyAddr;
|
mozilla::Unused << aProxyAddr;
|
||||||
mozilla::Unused << aDomainSocketPath;
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -489,12 +496,12 @@ nsSOCKSSocketInfo::ConnectToProxy(PRFileDesc *fd)
|
||||||
|
|
||||||
int32_t addresses = 0;
|
int32_t addresses = 0;
|
||||||
do {
|
do {
|
||||||
if (IsHostDomainSocket()) {
|
if (IsLocalProxy()) {
|
||||||
rv = SetDomainSocketPath(proxyHost, &mInternalProxyAddr);
|
rv = SetLocalProxyPath(proxyHost, &mInternalProxyAddr);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
LOGERROR(("socks: unable to connect to SOCKS proxy, %s",
|
LOGERROR(("socks: unable to connect to SOCKS proxy, %s",
|
||||||
proxyHost.get()));
|
proxyHost.get()));
|
||||||
return PR_FAILURE;
|
return PR_FAILURE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (addresses++) {
|
if (addresses++) {
|
||||||
|
@ -529,7 +536,7 @@ nsSOCKSSocketInfo::ConnectToProxy(PRFileDesc *fd)
|
||||||
if (c == PR_WOULD_BLOCK_ERROR || c == PR_IN_PROGRESS_ERROR) {
|
if (c == PR_WOULD_BLOCK_ERROR || c == PR_IN_PROGRESS_ERROR) {
|
||||||
mState = SOCKS_CONNECTING_TO_PROXY;
|
mState = SOCKS_CONNECTING_TO_PROXY;
|
||||||
return status;
|
return status;
|
||||||
} else if (IsHostDomainSocket()) {
|
} else if (IsLocalProxy()) {
|
||||||
LOGERROR(("socks: connect to domain socket failed (%d)", c));
|
LOGERROR(("socks: connect to domain socket failed (%d)", c));
|
||||||
PR_SetError(PR_CONNECT_REFUSED_ERROR, 0);
|
PR_SetError(PR_CONNECT_REFUSED_ERROR, 0);
|
||||||
mState = SOCKS_FAILED;
|
mState = SOCKS_FAILED;
|
||||||
|
@ -1049,7 +1056,7 @@ nsSOCKSSocketInfo::DoHandshake(PRFileDesc *fd, int16_t oflags)
|
||||||
|
|
||||||
switch (mState) {
|
switch (mState) {
|
||||||
case SOCKS_INITIAL:
|
case SOCKS_INITIAL:
|
||||||
if (IsHostDomainSocket()) {
|
if (IsLocalProxy()) {
|
||||||
mState = SOCKS_DNS_COMPLETE;
|
mState = SOCKS_DNS_COMPLETE;
|
||||||
mLookupStatus = NS_OK;
|
mLookupStatus = NS_OK;
|
||||||
return ConnectToProxy(fd);
|
return ConnectToProxy(fd);
|
||||||
|
@ -1535,3 +1542,15 @@ nsSOCKSIOLayerAddToSocket(int32_t family,
|
||||||
NS_ADDREF(*info);
|
NS_ADDREF(*info);
|
||||||
return NS_OK;
|
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,
|
PRFileDesc *fd,
|
||||||
nsISupports **info);
|
nsISupports **info);
|
||||||
|
|
||||||
|
bool IsHostLocalTarget(const nsACString& aHost);
|
||||||
|
|
||||||
#endif /* nsSOCKSIOLayer_h__ */
|
#endif /* nsSOCKSIOLayer_h__ */
|
||||||
|
|
|
@ -168,7 +168,7 @@ union PRNetAddr {
|
||||||
PRIPv6Addr ip; /* the actual 128 bits of address */
|
PRIPv6Addr ip; /* the actual 128 bits of address */
|
||||||
PRUint32 scope_id; /* set of interfaces for a scope */
|
PRUint32 scope_id; /* set of interfaces for a scope */
|
||||||
} ipv6;
|
} ipv6;
|
||||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
#if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_WIN)
|
||||||
struct { /* Unix domain socket address */
|
struct { /* Unix domain socket address */
|
||||||
PRUint16 family; /* address family (AF_UNIX) */
|
PRUint16 family; /* address family (AF_UNIX) */
|
||||||
#ifdef XP_OS2
|
#ifdef XP_OS2
|
||||||
|
|
Загрузка…
Ссылка в новой задаче