/work/obj-fuzz/dist/include/mozilla/net/PHttpChannelParams.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
20 | | namespace mozilla { |
21 | | namespace net { |
22 | | |
23 | | struct RequestHeaderTuple { |
24 | | nsCString mHeader; |
25 | | nsCString mValue; |
26 | | bool mMerge; |
27 | | bool mEmpty; |
28 | | |
29 | 0 | bool operator ==(const RequestHeaderTuple &other) const { |
30 | 0 | return mHeader.Equals(other.mHeader) && |
31 | 0 | mValue.Equals(other.mValue) && |
32 | 0 | mMerge == other.mMerge && |
33 | 0 | mEmpty == other.mEmpty; |
34 | 0 | } |
35 | | }; |
36 | | |
37 | | typedef nsTArray<RequestHeaderTuple> RequestHeaderTuples; |
38 | | |
39 | | } // namespace net |
40 | | } // namespace mozilla |
41 | | |
42 | | namespace IPC { |
43 | | |
44 | | template<> |
45 | | struct ParamTraits<mozilla::net::RequestHeaderTuple> |
46 | | { |
47 | | typedef mozilla::net::RequestHeaderTuple paramType; |
48 | | |
49 | | static void Write(Message* aMsg, const paramType& aParam) |
50 | 0 | { |
51 | 0 | WriteParam(aMsg, aParam.mHeader); |
52 | 0 | WriteParam(aMsg, aParam.mValue); |
53 | 0 | WriteParam(aMsg, aParam.mMerge); |
54 | 0 | WriteParam(aMsg, aParam.mEmpty); |
55 | 0 | } |
56 | | |
57 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
58 | 0 | { |
59 | 0 | if (!ReadParam(aMsg, aIter, &aResult->mHeader) || |
60 | 0 | !ReadParam(aMsg, aIter, &aResult->mValue) || |
61 | 0 | !ReadParam(aMsg, aIter, &aResult->mMerge) || |
62 | 0 | !ReadParam(aMsg, aIter, &aResult->mEmpty)) |
63 | 0 | return false; |
64 | 0 | |
65 | 0 | return true; |
66 | 0 | } |
67 | | }; |
68 | | |
69 | | template<> |
70 | | struct ParamTraits<mozilla::net::nsHttpAtom> |
71 | | { |
72 | | typedef mozilla::net::nsHttpAtom paramType; |
73 | | |
74 | | static void Write(Message* aMsg, const paramType& aParam) |
75 | 0 | { |
76 | 0 | // aParam.get() cannot be null. |
77 | 0 | MOZ_ASSERT(aParam.get(), "null nsHTTPAtom value"); |
78 | 0 | nsAutoCString value(aParam.get()); |
79 | 0 | WriteParam(aMsg, value); |
80 | 0 | } |
81 | | |
82 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
83 | 0 | { |
84 | 0 | nsAutoCString value; |
85 | 0 | if (!ReadParam(aMsg, aIter, &value)) |
86 | 0 | return false; |
87 | 0 |
|
88 | 0 | *aResult = mozilla::net::nsHttp::ResolveAtom(value.get()); |
89 | 0 | MOZ_ASSERT(aResult->get(), "atom table not initialized"); |
90 | 0 | return true; |
91 | 0 | } |
92 | | }; |
93 | | |
94 | | template<> |
95 | | struct ParamTraits<mozilla::net::nsHttpHeaderArray::nsEntry> |
96 | | { |
97 | | typedef mozilla::net::nsHttpHeaderArray::nsEntry paramType; |
98 | | |
99 | | static void Write(Message* aMsg, const paramType& aParam) |
100 | 0 | { |
101 | 0 | if (aParam.headerNameOriginal.IsEmpty()) { |
102 | 0 | WriteParam(aMsg, aParam.header); |
103 | 0 | } else { |
104 | 0 | WriteParam(aMsg, aParam.headerNameOriginal); |
105 | 0 | } |
106 | 0 | WriteParam(aMsg, aParam.value); |
107 | 0 | switch (aParam.variety) { |
108 | 0 | case mozilla::net::nsHttpHeaderArray::eVarietyUnknown: |
109 | 0 | WriteParam(aMsg, (uint8_t)0); |
110 | 0 | break; |
111 | 0 | case mozilla::net::nsHttpHeaderArray::eVarietyRequestOverride: |
112 | 0 | WriteParam(aMsg, (uint8_t)1); |
113 | 0 | break; |
114 | 0 | case mozilla::net::nsHttpHeaderArray::eVarietyRequestDefault: |
115 | 0 | WriteParam(aMsg, (uint8_t)2); |
116 | 0 | break; |
117 | 0 | case mozilla::net::nsHttpHeaderArray::eVarietyResponseNetOriginalAndResponse: |
118 | 0 | WriteParam(aMsg, (uint8_t)3); |
119 | 0 | break; |
120 | 0 | case mozilla::net::nsHttpHeaderArray::eVarietyResponseNetOriginal: |
121 | 0 | WriteParam(aMsg, (uint8_t)4); |
122 | 0 | break; |
123 | 0 | case mozilla::net::nsHttpHeaderArray::eVarietyResponse: |
124 | 0 | WriteParam(aMsg, (uint8_t)5); |
125 | 0 | } |
126 | 0 | } |
127 | | |
128 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
129 | 0 | { |
130 | 0 | uint8_t variety; |
131 | 0 | nsAutoCString header; |
132 | 0 | if (!ReadParam(aMsg, aIter, &header) || |
133 | 0 | !ReadParam(aMsg, aIter, &aResult->value) || |
134 | 0 | !ReadParam(aMsg, aIter, &variety)) |
135 | 0 | return false; |
136 | 0 | |
137 | 0 | mozilla::net::nsHttpAtom atom = mozilla::net::nsHttp::ResolveAtom(header); |
138 | 0 | aResult->header = atom; |
139 | 0 | if (!header.Equals(atom.get())) { |
140 | 0 | aResult->headerNameOriginal = header; |
141 | 0 | } |
142 | 0 |
|
143 | 0 | switch (variety) { |
144 | 0 | case 0: |
145 | 0 | aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyUnknown; |
146 | 0 | break; |
147 | 0 | case 1: |
148 | 0 | aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyRequestOverride; |
149 | 0 | break; |
150 | 0 | case 2: |
151 | 0 | aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyRequestDefault; |
152 | 0 | break; |
153 | 0 | case 3: |
154 | 0 | aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyResponseNetOriginalAndResponse; |
155 | 0 | break; |
156 | 0 | case 4: |
157 | 0 | aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyResponseNetOriginal; |
158 | 0 | break; |
159 | 0 | case 5: |
160 | 0 | aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyResponse; |
161 | 0 | break; |
162 | 0 | default: |
163 | 0 | return false; |
164 | 0 | } |
165 | 0 | |
166 | 0 | return true; |
167 | 0 | } |
168 | | }; |
169 | | |
170 | | |
171 | | template<> |
172 | | struct ParamTraits<mozilla::net::nsHttpHeaderArray> |
173 | | { |
174 | | typedef mozilla::net::nsHttpHeaderArray paramType; |
175 | | |
176 | | static void Write(Message* aMsg, const paramType& aParam) |
177 | 0 | { |
178 | 0 | paramType& p = const_cast<paramType&>(aParam); |
179 | 0 |
|
180 | 0 | WriteParam(aMsg, p.mHeaders); |
181 | 0 | } |
182 | | |
183 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
184 | 0 | { |
185 | 0 | if (!ReadParam(aMsg, aIter, &aResult->mHeaders)) |
186 | 0 | return false; |
187 | 0 | |
188 | 0 | return true; |
189 | 0 | } |
190 | | }; |
191 | | |
192 | | template<> |
193 | | struct ParamTraits<mozilla::net::nsHttpResponseHead> |
194 | | { |
195 | | typedef mozilla::net::nsHttpResponseHead paramType; |
196 | | |
197 | | static void Write(Message* aMsg, const paramType& aParam) |
198 | 0 | { |
199 | 0 | WriteParam(aMsg, aParam.mHeaders); |
200 | 0 | WriteParam(aMsg, static_cast<uint32_t>(aParam.mVersion)); |
201 | 0 | WriteParam(aMsg, aParam.mStatus); |
202 | 0 | WriteParam(aMsg, aParam.mStatusText); |
203 | 0 | WriteParam(aMsg, aParam.mContentLength); |
204 | 0 | WriteParam(aMsg, aParam.mContentType); |
205 | 0 | WriteParam(aMsg, aParam.mContentCharset); |
206 | 0 | WriteParam(aMsg, aParam.mCacheControlPrivate); |
207 | 0 | WriteParam(aMsg, aParam.mCacheControlNoStore); |
208 | 0 | WriteParam(aMsg, aParam.mCacheControlNoCache); |
209 | 0 | WriteParam(aMsg, aParam.mPragmaNoCache); |
210 | 0 | } |
211 | | |
212 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
213 | 0 | { |
214 | 0 | uint32_t version; |
215 | 0 | if (!ReadParam(aMsg, aIter, &aResult->mHeaders) || |
216 | 0 | !ReadParam(aMsg, aIter, &version) || |
217 | 0 | !ReadParam(aMsg, aIter, &aResult->mStatus) || |
218 | 0 | !ReadParam(aMsg, aIter, &aResult->mStatusText) || |
219 | 0 | !ReadParam(aMsg, aIter, &aResult->mContentLength) || |
220 | 0 | !ReadParam(aMsg, aIter, &aResult->mContentType) || |
221 | 0 | !ReadParam(aMsg, aIter, &aResult->mContentCharset) || |
222 | 0 | !ReadParam(aMsg, aIter, &aResult->mCacheControlPrivate) || |
223 | 0 | !ReadParam(aMsg, aIter, &aResult->mCacheControlNoStore) || |
224 | 0 | !ReadParam(aMsg, aIter, &aResult->mCacheControlNoCache) || |
225 | 0 | !ReadParam(aMsg, aIter, &aResult->mPragmaNoCache)) |
226 | 0 | return false; |
227 | 0 | |
228 | 0 | aResult->mVersion = static_cast<mozilla::net::HttpVersion>(version); |
229 | 0 | return true; |
230 | 0 | } |
231 | | }; |
232 | | |
233 | | } // namespace IPC |
234 | | |
235 | | #endif // mozilla_net_PHttpChannelParams_h |