netwerk/protocol/http/PHttpChannelParams.h

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:0cf16d94d71c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef mozilla_net_PHttpChannelParams_h
8 #define mozilla_net_PHttpChannelParams_h
9
10 #define ALLOW_LATE_NSHTTP_H_INCLUDE 1
11 #include "base/basictypes.h"
12
13 #include "ipc/IPCMessageUtils.h"
14 #include "nsHttp.h"
15 #include "nsHttpHeaderArray.h"
16 #include "nsHttpResponseHead.h"
17
18 #include "nsIClassInfo.h"
19 #include "nsNetUtil.h"
20
21 namespace mozilla {
22 namespace net {
23
24 struct RequestHeaderTuple {
25 nsCString mHeader;
26 nsCString mValue;
27 bool mMerge;
28
29 bool operator ==(const RequestHeaderTuple &other) const {
30 return mHeader.Equals(other.mHeader) &&
31 mValue.Equals(other.mValue) &&
32 mMerge == other.mMerge;
33 }
34 };
35
36 typedef nsTArray<RequestHeaderTuple> RequestHeaderTuples;
37
38 } // namespace net
39 } // namespace mozilla
40
41 namespace IPC {
42
43 template<>
44 struct ParamTraits<mozilla::net::RequestHeaderTuple>
45 {
46 typedef mozilla::net::RequestHeaderTuple paramType;
47
48 static void Write(Message* aMsg, const paramType& aParam)
49 {
50 WriteParam(aMsg, aParam.mHeader);
51 WriteParam(aMsg, aParam.mValue);
52 WriteParam(aMsg, aParam.mMerge);
53 }
54
55 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
56 {
57 if (!ReadParam(aMsg, aIter, &aResult->mHeader) ||
58 !ReadParam(aMsg, aIter, &aResult->mValue) ||
59 !ReadParam(aMsg, aIter, &aResult->mMerge))
60 return false;
61
62 return true;
63 }
64 };
65
66 template<>
67 struct ParamTraits<mozilla::net::nsHttpAtom>
68 {
69 typedef mozilla::net::nsHttpAtom paramType;
70
71 static void Write(Message* aMsg, const paramType& aParam)
72 {
73 // aParam.get() cannot be null.
74 MOZ_ASSERT(aParam.get(), "null nsHTTPAtom value");
75 nsAutoCString value(aParam.get());
76 WriteParam(aMsg, value);
77 }
78
79 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
80 {
81 nsAutoCString value;
82 if (!ReadParam(aMsg, aIter, &value))
83 return false;
84
85 *aResult = mozilla::net::nsHttp::ResolveAtom(value.get());
86 MOZ_ASSERT(aResult->get(), "atom table not initialized");
87 return true;
88 }
89 };
90
91 template<>
92 struct ParamTraits<mozilla::net::nsHttpHeaderArray::nsEntry>
93 {
94 typedef mozilla::net::nsHttpHeaderArray::nsEntry paramType;
95
96 static void Write(Message* aMsg, const paramType& aParam)
97 {
98 WriteParam(aMsg, aParam.header);
99 WriteParam(aMsg, aParam.value);
100 }
101
102 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
103 {
104 if (!ReadParam(aMsg, aIter, &aResult->header) ||
105 !ReadParam(aMsg, aIter, &aResult->value))
106 return false;
107
108 return true;
109 }
110 };
111
112
113 template<>
114 struct ParamTraits<mozilla::net::nsHttpHeaderArray>
115 {
116 typedef mozilla::net::nsHttpHeaderArray paramType;
117
118 static void Write(Message* aMsg, const paramType& aParam)
119 {
120 paramType& p = const_cast<paramType&>(aParam);
121
122 WriteParam(aMsg, p.mHeaders);
123 }
124
125 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
126 {
127 if (!ReadParam(aMsg, aIter, &aResult->mHeaders))
128 return false;
129
130 return true;
131 }
132 };
133
134 template<>
135 struct ParamTraits<mozilla::net::nsHttpResponseHead>
136 {
137 typedef mozilla::net::nsHttpResponseHead paramType;
138
139 static void Write(Message* aMsg, const paramType& aParam)
140 {
141 WriteParam(aMsg, aParam.mHeaders);
142 WriteParam(aMsg, aParam.mVersion);
143 WriteParam(aMsg, aParam.mStatus);
144 WriteParam(aMsg, aParam.mStatusText);
145 WriteParam(aMsg, aParam.mContentLength);
146 WriteParam(aMsg, aParam.mContentType);
147 WriteParam(aMsg, aParam.mContentCharset);
148 WriteParam(aMsg, aParam.mCacheControlNoStore);
149 WriteParam(aMsg, aParam.mCacheControlNoCache);
150 WriteParam(aMsg, aParam.mPragmaNoCache);
151 }
152
153 static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
154 {
155 if (!ReadParam(aMsg, aIter, &aResult->mHeaders) ||
156 !ReadParam(aMsg, aIter, &aResult->mVersion) ||
157 !ReadParam(aMsg, aIter, &aResult->mStatus) ||
158 !ReadParam(aMsg, aIter, &aResult->mStatusText) ||
159 !ReadParam(aMsg, aIter, &aResult->mContentLength) ||
160 !ReadParam(aMsg, aIter, &aResult->mContentType) ||
161 !ReadParam(aMsg, aIter, &aResult->mContentCharset) ||
162 !ReadParam(aMsg, aIter, &aResult->mCacheControlNoStore) ||
163 !ReadParam(aMsg, aIter, &aResult->mCacheControlNoCache) ||
164 !ReadParam(aMsg, aIter, &aResult->mPragmaNoCache))
165 return false;
166
167 return true;
168 }
169 };
170
171 } // namespace IPC
172
173 #endif // mozilla_net_PHttpChannelParams_h

mercurial