bug 648878 - move get(local|remote)(address|port) to httpchannelchild, r=jduell

This commit is contained in:
Nick Hurley 2011-05-03 17:47:05 -04:00
parent 9cfec7bd80
commit d9b9d8ca90
9 changed files with 161 additions and 77 deletions

View File

@ -47,6 +47,7 @@
#include "nsComponentManagerUtils.h"
#include "nsNetUtil.h"
#include "nsStringStream.h"
#include "prio.h"
namespace IPC {
@ -325,6 +326,60 @@ struct ParamTraits<Permission>
}
};
template<>
struct ParamTraits<PRNetAddr>
{
static void Write(Message* aMsg, const PRNetAddr &aParam)
{
WriteParam(aMsg, aParam.raw.family);
if (aParam.raw.family == PR_AF_UNSPEC) {
aMsg->WriteBytes(aParam.raw.data, sizeof(aParam.raw.data));
} else if (aParam.raw.family == PR_AF_INET) {
WriteParam(aMsg, aParam.inet.port);
WriteParam(aMsg, aParam.inet.ip);
} else if (aParam.raw.family == PR_AF_INET6) {
WriteParam(aMsg, aParam.ipv6.port);
WriteParam(aMsg, aParam.ipv6.flowinfo);
WriteParam(aMsg, aParam.ipv6.ip.pr_s6_addr64[0]);
WriteParam(aMsg, aParam.ipv6.ip.pr_s6_addr64[1]);
WriteParam(aMsg, aParam.ipv6.scope_id);
} else if (aParam.raw.family == PR_AF_LOCAL) {
aMsg->WriteBytes(aParam.local.path, sizeof(aParam.local.path));
}
/* If we get here without hitting any of the cases above, there's not much
* we can do but let the deserializer fail when it gets this message */
}
static bool Read(const Message* aMsg, void** aIter, PRNetAddr* aResult)
{
if (!ReadParam(aMsg, aIter, &aResult->raw.family))
return false;
if (aResult->raw.family == PR_AF_UNSPEC) {
return aMsg->ReadBytes(aIter,
reinterpret_cast<const char**>(&aResult->raw.data),
sizeof(aResult->raw.data));
} else if (aResult->raw.family == PR_AF_INET) {
return ReadParam(aMsg, aIter, &aResult->inet.port) &&
ReadParam(aMsg, aIter, &aResult->inet.ip);
} else if (aResult->raw.family == PR_AF_INET6) {
return ReadParam(aMsg, aIter, &aResult->ipv6.port) &&
ReadParam(aMsg, aIter, &aResult->ipv6.flowinfo) &&
ReadParam(aMsg, aIter, &aResult->ipv6.ip.pr_s6_addr64[0]) &&
ReadParam(aMsg, aIter, &aResult->ipv6.ip.pr_s6_addr64[1]) &&
ReadParam(aMsg, aIter, &aResult->ipv6.scope_id);
} else if (aResult->raw.family == PR_AF_LOCAL) {
return aMsg->ReadBytes(aIter,
reinterpret_cast<const char**>(&aResult->local.path),
sizeof(aResult->local.path));
}
/* We've been tricked by some socket family we don't know about! */
return false;
}
};
}
#endif // mozilla_net_NeckoMessageUtils_h

View File

@ -54,6 +54,8 @@
#include "nsEscape.h"
#include "nsPrintfCString.h"
#include "prnetdb.h"
namespace mozilla {
namespace net {
@ -1177,6 +1179,66 @@ HttpBaseChannel::SetCacheKeysRedirectChain(nsTArray<nsCString> *cacheKeys)
return NS_OK;
}
NS_IMETHODIMP
HttpBaseChannel::GetLocalAddress(nsACString& addr)
{
if (mSelfAddr.raw.family == PR_AF_UNSPEC)
return NS_ERROR_NOT_AVAILABLE;
addr.SetCapacity(64);
PR_NetAddrToString(&mSelfAddr, addr.BeginWriting(), 64);
addr.SetLength(strlen(addr.BeginReading()));
return NS_OK;
}
NS_IMETHODIMP
HttpBaseChannel::GetLocalPort(PRInt32* port)
{
NS_ENSURE_ARG_POINTER(port);
if (mSelfAddr.raw.family == PR_AF_INET) {
*port = (PRInt32)PR_ntohs(mSelfAddr.inet.port);
}
else if (mSelfAddr.raw.family == PR_AF_INET6) {
*port = (PRInt32)PR_ntohs(mSelfAddr.ipv6.port);
}
else
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
NS_IMETHODIMP
HttpBaseChannel::GetRemoteAddress(nsACString& addr)
{
if (mPeerAddr.raw.family == PR_AF_UNSPEC)
return NS_ERROR_NOT_AVAILABLE;
addr.SetCapacity(64);
PR_NetAddrToString(&mPeerAddr, addr.BeginWriting(), 64);
addr.SetLength(strlen(addr.BeginReading()));
return NS_OK;
}
NS_IMETHODIMP
HttpBaseChannel::GetRemotePort(PRInt32* port)
{
NS_ENSURE_ARG_POINTER(port);
if (mPeerAddr.raw.family == PR_AF_INET) {
*port = (PRInt32)PR_ntohs(mPeerAddr.inet.port);
}
else if (mPeerAddr.raw.family == PR_AF_INET6) {
*port = (PRInt32)PR_ntohs(mPeerAddr.ipv6.port);
}
else
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
//-----------------------------------------------------------------------------
// HttpBaseChannel::nsISupportsPriority
//-----------------------------------------------------------------------------

View File

@ -155,6 +155,10 @@ public:
NS_IMETHOD GetChannelIsForDownload(PRBool *aChannelIsForDownload);
NS_IMETHOD SetChannelIsForDownload(PRBool aChannelIsForDownload);
NS_IMETHOD SetCacheKeysRedirectChain(nsTArray<nsCString> *cacheKeys);
NS_IMETHOD GetLocalAddress(nsACString& addr);
NS_IMETHOD GetLocalPort(PRInt32* port);
NS_IMETHOD GetRemoteAddress(nsACString& addr);
NS_IMETHOD GetRemotePort(PRInt32* port);
inline void CleanRedirectCacheChainIfNecessary()
{
if (mRedirectedCachekeys) {
@ -197,6 +201,9 @@ public:
nsHttpResponseHead * GetResponseHead() const { return mResponseHead; }
nsHttpRequestHead * GetRequestHead() { return &mRequestHead; }
const PRNetAddr& GetSelfAddr() { return mSelfAddr; }
const PRNetAddr& GetPeerAddr() { return mPeerAddr; }
protected:
nsresult ApplyContentConversions();
@ -236,6 +243,9 @@ protected:
nsCString mContentCharsetHint;
nsCString mUserSetCookieHeader;
PRNetAddr mSelfAddr;
PRNetAddr mPeerAddr;
// Resumable channel specific data
nsCString mEntityID;
PRUint64 mStartPos;

View File

@ -155,7 +155,9 @@ class StartRequestEvent : public ChannelEvent
const PRBool& cacheEntryAvailable,
const PRUint32& cacheExpirationTime,
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization)
const nsCString& securityInfoSerialization,
const PRNetAddr& selfAddr,
const PRNetAddr& peerAddr)
: mChild(child)
, mResponseHead(responseHead)
, mRequestHeaders(requestHeaders)
@ -165,6 +167,8 @@ class StartRequestEvent : public ChannelEvent
, mCacheExpirationTime(cacheExpirationTime)
, mCachedCharset(cachedCharset)
, mSecurityInfoSerialization(securityInfoSerialization)
, mSelfAddr(selfAddr)
, mPeerAddr(peerAddr)
{}
void Run()
@ -172,7 +176,7 @@ class StartRequestEvent : public ChannelEvent
mChild->OnStartRequest(mResponseHead, mUseResponseHead, mRequestHeaders,
mIsFromCache, mCacheEntryAvailable,
mCacheExpirationTime, mCachedCharset,
mSecurityInfoSerialization);
mSecurityInfoSerialization, mSelfAddr, mPeerAddr);
}
private:
HttpChannelChild* mChild;
@ -184,6 +188,8 @@ class StartRequestEvent : public ChannelEvent
PRUint32 mCacheExpirationTime;
nsCString mCachedCharset;
nsCString mSecurityInfoSerialization;
PRNetAddr mSelfAddr;
PRNetAddr mPeerAddr;
};
bool
@ -209,18 +215,21 @@ HttpChannelChild::RecvOnStartRequest(const nsHttpResponseHead& responseHead,
const PRBool& cacheEntryAvailable,
const PRUint32& cacheExpirationTime,
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization)
const nsCString& securityInfoSerialization,
const PRNetAddr& selfAddr,
const PRNetAddr& peerAddr)
{
if (ShouldEnqueue()) {
EnqueueEvent(new StartRequestEvent(this, responseHead, useResponseHead,
requestHeaders,
isFromCache, cacheEntryAvailable,
cacheExpirationTime, cachedCharset,
securityInfoSerialization));
securityInfoSerialization, selfAddr,
peerAddr));
} else {
OnStartRequest(responseHead, useResponseHead, requestHeaders, isFromCache,
cacheEntryAvailable, cacheExpirationTime, cachedCharset,
securityInfoSerialization);
securityInfoSerialization, selfAddr, peerAddr);
}
return true;
}
@ -233,7 +242,9 @@ HttpChannelChild::OnStartRequest(const nsHttpResponseHead& responseHead,
const PRBool& cacheEntryAvailable,
const PRUint32& cacheExpirationTime,
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization)
const nsCString& securityInfoSerialization,
const PRNetAddr& selfAddr,
const PRNetAddr& peerAddr)
{
LOG(("HttpChannelChild::RecvOnStartRequest [this=%x]\n", this));
@ -271,6 +282,9 @@ HttpChannelChild::OnStartRequest(const nsHttpResponseHead& responseHead,
rv = ApplyContentConversions();
if (NS_FAILED(rv))
Cancel(rv);
mSelfAddr = selfAddr;
mPeerAddr = peerAddr;
}
class TransportAndDataEvent : public ChannelEvent

View File

@ -134,7 +134,9 @@ protected:
const PRBool& cacheEntryAvailable,
const PRUint32& cacheExpirationTime,
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization);
const nsCString& securityInfoSerialization,
const PRNetAddr& selfAddr,
const PRNetAddr& peerAddr);
bool RecvOnTransportAndData(const nsresult& status,
const PRUint64& progress,
const PRUint64& progressMax,
@ -182,7 +184,9 @@ private:
const PRBool& cacheEntryAvailable,
const PRUint32& cacheExpirationTime,
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization);
const nsCString& securityInfoSerialization,
const PRNetAddr& selfAddr,
const PRNetAddr& peerAddr);
void OnTransportAndData(const nsresult& status,
const PRUint64 progress,
const PRUint64& progressMax,

View File

@ -430,13 +430,15 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
tuple->mMerge = false;
}
nsHttpChannel *httpChan = static_cast<nsHttpChannel *>(mChannel.get());
if (mIPCClosed ||
!SendOnStartRequest(responseHead ? *responseHead : nsHttpResponseHead(),
!!responseHead,
headers,
isFromCache,
mCacheDescriptor ? PR_TRUE : PR_FALSE,
expirationTime, cachedCharset, secInfoSerialization))
expirationTime, cachedCharset, secInfoSerialization,
httpChan->GetSelfAddr(), httpChan->GetPeerAddr()))
{
return NS_ERROR_UNEXPECTED;
}

View File

@ -43,12 +43,14 @@ include protocol PNecko;
include "mozilla/net/PHttpChannelParams.h";
include "mozilla/net/NeckoMessageUtils.h";
include "prio.h";
using RequestHeaderTuples;
using nsHttpResponseHead;
using nsHttpAtom;
using IPC::URI;
using IPC::InputStream;
using PRNetAddr;
namespace mozilla {
namespace net {
@ -131,7 +133,9 @@ child:
PRBool cacheEntryAvailable,
PRUint32 cacheExpirationTime,
nsCString cachedCharset,
nsCString securityInfoSerialization);
nsCString securityInfoSerialization,
PRNetAddr selfAddr,
PRNetAddr peerAddr);
// Combines a single OnDataAvailable and its associated OnProgress &
// OnStatus calls into one IPDL message

View File

@ -3714,66 +3714,6 @@ nsHttpChannel::SetupFallbackChannel(const char *aFallbackKey)
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetRemoteAddress(nsACString & _result)
{
if (mPeerAddr.raw.family == PR_AF_UNSPEC)
return NS_ERROR_NOT_AVAILABLE;
_result.SetCapacity(64);
PR_NetAddrToString(&mPeerAddr, _result.BeginWriting(), 64);
_result.SetLength(strlen(_result.BeginReading()));
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetRemotePort(PRInt32 * _result)
{
NS_ENSURE_ARG_POINTER(_result);
if (mPeerAddr.raw.family == PR_AF_INET) {
*_result = (PRInt32)PR_ntohs(mPeerAddr.inet.port);
}
else if (mPeerAddr.raw.family == PR_AF_INET6) {
*_result = (PRInt32)PR_ntohs(mPeerAddr.ipv6.port);
}
else
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetLocalAddress(nsACString & _result)
{
if (mSelfAddr.raw.family == PR_AF_UNSPEC)
return NS_ERROR_NOT_AVAILABLE;
_result.SetCapacity(64);
PR_NetAddrToString(&mSelfAddr, _result.BeginWriting(), 64);
_result.SetLength(strlen(_result.BeginReading()));
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetLocalPort(PRInt32 * _result)
{
NS_ENSURE_ARG_POINTER(_result);
if (mSelfAddr.raw.family == PR_AF_INET) {
*_result = (PRInt32)PR_ntohs(mSelfAddr.inet.port);
}
else if (mSelfAddr.raw.family == PR_AF_INET6) {
*_result = (PRInt32)PR_ntohs(mSelfAddr.ipv6.port);
}
else
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsHttpChannel::nsISupportsPriority
//-----------------------------------------------------------------------------

View File

@ -137,10 +137,6 @@ public:
NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *aContext);
// nsIHttpChannelInternal
NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey);
NS_IMETHOD GetLocalAddress(nsACString& addr);
NS_IMETHOD GetLocalPort(PRInt32* port);
NS_IMETHOD GetRemoteAddress(nsACString& addr);
NS_IMETHOD GetRemotePort(PRInt32* port);
// nsISupportsPriority
NS_IMETHOD SetPriority(PRInt32 value);
// nsIResumableChannel
@ -351,9 +347,6 @@ private:
// the cache entry's expiration time. Otherwise, it is not(see bug 567360).
PRUint32 mRequestTimeInitialized : 1;
PRNetAddr mSelfAddr;
PRNetAddr mPeerAddr;
nsTArray<nsContinueRedirectionFunc> mRedirectFuncStack;
nsCOMPtr<nsICryptoHash> mHasher;