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 :
4 : /* ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : * The contents of this file are subject to the Mozilla Public License Version
8 : * 1.1 (the "License"); you may not use this file except in compliance with
9 : * the License. You may obtain a copy of the License at
10 : * http://www.mozilla.org/MPL/
11 : *
12 : * Software distributed under the License is distributed on an "AS IS" basis,
13 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 : * for the specific language governing rights and limitations under the
15 : * License.
16 : *
17 : * The Original Code is mozilla.org code.
18 : *
19 : * The Initial Developer of the Original Code is
20 : * The Mozilla Foundation
21 : * Portions created by the Initial Developer are Copyright (C) 2010
22 : * the Initial Developer. All Rights Reserved.
23 : *
24 : * Contributor(s):
25 : * Jae-Seong Lee-Russo <lusian@gmail.com>
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either the GNU General Public License Version 2 or later (the "GPL"), or
29 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 : #ifndef mozilla_net_PHttpChannelParams_h
42 : #define mozilla_net_PHttpChannelParams_h
43 :
44 : #define ALLOW_LATE_NSHTTP_H_INCLUDE 1
45 : #include "base/basictypes.h"
46 :
47 : #include "IPC/IPCMessageUtils.h"
48 : #include "nsHttp.h"
49 : #include "nsHttpHeaderArray.h"
50 : #include "nsHttpResponseHead.h"
51 :
52 : #include "nsIIPCSerializable.h"
53 : #include "nsIClassInfo.h"
54 : #include "nsNetUtil.h"
55 :
56 : namespace mozilla {
57 : namespace net {
58 :
59 0 : struct RequestHeaderTuple {
60 : nsCString mHeader;
61 : nsCString mValue;
62 : bool mMerge;
63 : };
64 :
65 : typedef nsTArray<RequestHeaderTuple> RequestHeaderTuples;
66 :
67 : } // namespace net
68 : } // namespace mozilla
69 :
70 : namespace IPC {
71 :
72 : template<>
73 : struct ParamTraits<mozilla::net::RequestHeaderTuple>
74 : {
75 : typedef mozilla::net::RequestHeaderTuple paramType;
76 :
77 0 : static void Write(Message* aMsg, const paramType& aParam)
78 : {
79 0 : WriteParam(aMsg, aParam.mHeader);
80 0 : WriteParam(aMsg, aParam.mValue);
81 0 : WriteParam(aMsg, aParam.mMerge);
82 0 : }
83 :
84 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
85 : {
86 0 : if (!ReadParam(aMsg, aIter, &aResult->mHeader) ||
87 0 : !ReadParam(aMsg, aIter, &aResult->mValue) ||
88 0 : !ReadParam(aMsg, aIter, &aResult->mMerge))
89 0 : return false;
90 :
91 0 : return true;
92 : }
93 : };
94 :
95 : template<>
96 : struct ParamTraits<nsHttpAtom>
97 : {
98 : typedef nsHttpAtom paramType;
99 :
100 0 : static void Write(Message* aMsg, const paramType& aParam)
101 : {
102 : // aParam.get() cannot be null.
103 0 : NS_ASSERTION(aParam.get(), "null nsHTTPAtom value");
104 0 : nsCAutoString value(aParam.get());
105 0 : WriteParam(aMsg, value);
106 0 : }
107 :
108 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
109 : {
110 0 : nsCAutoString value;
111 0 : if (!ReadParam(aMsg, aIter, &value))
112 0 : return false;
113 :
114 0 : *aResult = nsHttp::ResolveAtom(value.get());
115 0 : NS_ASSERTION(aResult->get(), "atom table not initialized");
116 0 : return true;
117 : }
118 : };
119 :
120 : template<>
121 : struct ParamTraits<nsHttpHeaderArray::nsEntry>
122 : {
123 : typedef nsHttpHeaderArray::nsEntry paramType;
124 :
125 0 : static void Write(Message* aMsg, const paramType& aParam)
126 : {
127 0 : WriteParam(aMsg, aParam.header);
128 0 : WriteParam(aMsg, aParam.value);
129 0 : }
130 :
131 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
132 : {
133 0 : if (!ReadParam(aMsg, aIter, &aResult->header) ||
134 0 : !ReadParam(aMsg, aIter, &aResult->value))
135 0 : return false;
136 :
137 0 : return true;
138 : }
139 : };
140 :
141 : template<>
142 : struct ParamTraits<nsHttpHeaderArray>
143 : {
144 : typedef nsHttpHeaderArray paramType;
145 :
146 0 : static void Write(Message* aMsg, const paramType& aParam)
147 : {
148 0 : paramType& p = const_cast<paramType&>(aParam);
149 :
150 0 : WriteParam(aMsg, p.mHeaders);
151 0 : }
152 :
153 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
154 : {
155 0 : if (!ReadParam(aMsg, aIter, &aResult->mHeaders))
156 0 : return false;
157 :
158 0 : return true;
159 : }
160 : };
161 :
162 : template<>
163 : struct ParamTraits<nsHttpResponseHead>
164 : {
165 : typedef nsHttpResponseHead paramType;
166 :
167 0 : static void Write(Message* aMsg, const paramType& aParam)
168 : {
169 0 : WriteParam(aMsg, aParam.mHeaders);
170 0 : WriteParam(aMsg, aParam.mVersion);
171 0 : WriteParam(aMsg, aParam.mStatus);
172 0 : WriteParam(aMsg, aParam.mStatusText);
173 0 : WriteParam(aMsg, aParam.mContentLength);
174 0 : WriteParam(aMsg, aParam.mContentType);
175 0 : WriteParam(aMsg, aParam.mContentCharset);
176 0 : WriteParam(aMsg, aParam.mCacheControlNoStore);
177 0 : WriteParam(aMsg, aParam.mCacheControlNoCache);
178 0 : WriteParam(aMsg, aParam.mPragmaNoCache);
179 0 : }
180 :
181 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
182 : {
183 0 : if (!ReadParam(aMsg, aIter, &aResult->mHeaders) ||
184 0 : !ReadParam(aMsg, aIter, &aResult->mVersion) ||
185 0 : !ReadParam(aMsg, aIter, &aResult->mStatus) ||
186 0 : !ReadParam(aMsg, aIter, &aResult->mStatusText) ||
187 0 : !ReadParam(aMsg, aIter, &aResult->mContentLength) ||
188 0 : !ReadParam(aMsg, aIter, &aResult->mContentType) ||
189 0 : !ReadParam(aMsg, aIter, &aResult->mContentCharset) ||
190 0 : !ReadParam(aMsg, aIter, &aResult->mCacheControlNoStore) ||
191 0 : !ReadParam(aMsg, aIter, &aResult->mCacheControlNoCache) ||
192 0 : !ReadParam(aMsg, aIter, &aResult->mPragmaNoCache))
193 0 : return false;
194 :
195 0 : return true;
196 : }
197 : };
198 :
199 : } // namespace IPC
200 :
201 : #endif // mozilla_net_PHttpChannelParams_h
|