michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_net_PHttpChannelParams_h michael@0: #define mozilla_net_PHttpChannelParams_h michael@0: michael@0: #define ALLOW_LATE_NSHTTP_H_INCLUDE 1 michael@0: #include "base/basictypes.h" michael@0: michael@0: #include "ipc/IPCMessageUtils.h" michael@0: #include "nsHttp.h" michael@0: #include "nsHttpHeaderArray.h" michael@0: #include "nsHttpResponseHead.h" michael@0: michael@0: #include "nsIClassInfo.h" michael@0: #include "nsNetUtil.h" michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: struct RequestHeaderTuple { michael@0: nsCString mHeader; michael@0: nsCString mValue; michael@0: bool mMerge; michael@0: michael@0: bool operator ==(const RequestHeaderTuple &other) const { michael@0: return mHeader.Equals(other.mHeader) && michael@0: mValue.Equals(other.mValue) && michael@0: mMerge == other.mMerge; michael@0: } michael@0: }; michael@0: michael@0: typedef nsTArray RequestHeaderTuples; michael@0: michael@0: } // namespace net michael@0: } // namespace mozilla michael@0: michael@0: namespace IPC { michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::net::RequestHeaderTuple paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mHeader); michael@0: WriteParam(aMsg, aParam.mValue); michael@0: WriteParam(aMsg, aParam.mMerge); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (!ReadParam(aMsg, aIter, &aResult->mHeader) || michael@0: !ReadParam(aMsg, aIter, &aResult->mValue) || michael@0: !ReadParam(aMsg, aIter, &aResult->mMerge)) michael@0: return false; michael@0: michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::net::nsHttpAtom paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: // aParam.get() cannot be null. michael@0: MOZ_ASSERT(aParam.get(), "null nsHTTPAtom value"); michael@0: nsAutoCString value(aParam.get()); michael@0: WriteParam(aMsg, value); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: nsAutoCString value; michael@0: if (!ReadParam(aMsg, aIter, &value)) michael@0: return false; michael@0: michael@0: *aResult = mozilla::net::nsHttp::ResolveAtom(value.get()); michael@0: MOZ_ASSERT(aResult->get(), "atom table not initialized"); michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::net::nsHttpHeaderArray::nsEntry paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.header); michael@0: WriteParam(aMsg, aParam.value); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (!ReadParam(aMsg, aIter, &aResult->header) || michael@0: !ReadParam(aMsg, aIter, &aResult->value)) michael@0: return false; michael@0: michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::net::nsHttpHeaderArray paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: paramType& p = const_cast(aParam); michael@0: michael@0: WriteParam(aMsg, p.mHeaders); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (!ReadParam(aMsg, aIter, &aResult->mHeaders)) michael@0: return false; michael@0: michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: template<> michael@0: struct ParamTraits michael@0: { michael@0: typedef mozilla::net::nsHttpResponseHead paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam) michael@0: { michael@0: WriteParam(aMsg, aParam.mHeaders); michael@0: WriteParam(aMsg, aParam.mVersion); michael@0: WriteParam(aMsg, aParam.mStatus); michael@0: WriteParam(aMsg, aParam.mStatusText); michael@0: WriteParam(aMsg, aParam.mContentLength); michael@0: WriteParam(aMsg, aParam.mContentType); michael@0: WriteParam(aMsg, aParam.mContentCharset); michael@0: WriteParam(aMsg, aParam.mCacheControlNoStore); michael@0: WriteParam(aMsg, aParam.mCacheControlNoCache); michael@0: WriteParam(aMsg, aParam.mPragmaNoCache); michael@0: } michael@0: michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: if (!ReadParam(aMsg, aIter, &aResult->mHeaders) || michael@0: !ReadParam(aMsg, aIter, &aResult->mVersion) || michael@0: !ReadParam(aMsg, aIter, &aResult->mStatus) || michael@0: !ReadParam(aMsg, aIter, &aResult->mStatusText) || michael@0: !ReadParam(aMsg, aIter, &aResult->mContentLength) || michael@0: !ReadParam(aMsg, aIter, &aResult->mContentType) || michael@0: !ReadParam(aMsg, aIter, &aResult->mContentCharset) || michael@0: !ReadParam(aMsg, aIter, &aResult->mCacheControlNoStore) || michael@0: !ReadParam(aMsg, aIter, &aResult->mCacheControlNoCache) || michael@0: !ReadParam(aMsg, aIter, &aResult->mPragmaNoCache)) michael@0: return false; michael@0: michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: } // namespace IPC michael@0: michael@0: #endif // mozilla_net_PHttpChannelParams_h