OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 30 matching lines...) Expand all Loading... |
41 static inline void append(Vector<char>& buffer, const char* string) | 41 static inline void append(Vector<char>& buffer, const char* string) |
42 { | 42 { |
43 buffer.append(string, strlen(string)); | 43 buffer.append(string, strlen(string)); |
44 } | 44 } |
45 | 45 |
46 static inline void append(Vector<char>& buffer, const CString& string) | 46 static inline void append(Vector<char>& buffer, const CString& string) |
47 { | 47 { |
48 buffer.append(string.data(), string.length()); | 48 buffer.append(string.data(), string.length()); |
49 } | 49 } |
50 | 50 |
| 51 static inline void appendPercentEncoded(Vector<char>& buffer, unsigned char c) |
| 52 { |
| 53 append(buffer, '%'); |
| 54 appendByteAsHex(c, buffer); |
| 55 } |
| 56 |
51 static void appendQuotedString(Vector<char>& buffer, const CString& string) | 57 static void appendQuotedString(Vector<char>& buffer, const CString& string) |
52 { | 58 { |
53 // Append a string as a quoted value, escaping quotes and line breaks. | 59 // Append a string as a quoted value, escaping quotes and line breaks. |
54 // FIXME: Is it correct to use percent escaping here? Other browsers do not
encode these characters yet, | 60 // FIXME: Is it correct to use percent escaping here? Other browsers do not
encode these characters yet, |
55 // so we should test popular servers to find out if there is an encoding for
m they can handle. | 61 // so we should test popular servers to find out if there is an encoding for
m they can handle. |
56 size_t length = string.length(); | 62 size_t length = string.length(); |
57 for (size_t i = 0; i < length; ++i) { | 63 for (size_t i = 0; i < length; ++i) { |
58 char c = string.data()[i]; | 64 char c = string.data()[i]; |
59 | 65 |
60 switch (c) { | 66 switch (c) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 { | 176 { |
171 append(buffer, "\r\nContent-Type: "); | 177 append(buffer, "\r\nContent-Type: "); |
172 append(buffer, mimeType); | 178 append(buffer, mimeType); |
173 } | 179 } |
174 | 180 |
175 void FormDataEncoder::finishMultiPartHeader(Vector<char>& buffer) | 181 void FormDataEncoder::finishMultiPartHeader(Vector<char>& buffer) |
176 { | 182 { |
177 append(buffer, "\r\n\r\n"); | 183 append(buffer, "\r\n\r\n"); |
178 } | 184 } |
179 | 185 |
180 void FormDataEncoder::addKeyValuePairAsFormData(Vector<char>& buffer, const CStr
ing& key, const CString& value, EncodedFormData::EncodingType encodingType) | 186 void FormDataEncoder::addKeyValuePairAsFormData(Vector<char>& buffer, const CStr
ing& key, const CString& value, EncodedFormData::EncodingType encodingType, Mode
mode) |
181 { | 187 { |
182 if (encodingType == EncodedFormData::TextPlain) { | 188 if (encodingType == EncodedFormData::TextPlain) { |
183 if (!buffer.isEmpty()) | 189 if (!buffer.isEmpty()) |
184 append(buffer, "\r\n"); | 190 append(buffer, "\r\n"); |
185 append(buffer, key); | 191 append(buffer, key); |
186 append(buffer, '='); | 192 append(buffer, '='); |
187 append(buffer, value); | 193 append(buffer, value); |
188 } else { | 194 } else { |
189 if (!buffer.isEmpty()) | 195 if (!buffer.isEmpty()) |
190 append(buffer, '&'); | 196 append(buffer, '&'); |
191 encodeStringAsFormData(buffer, key); | 197 encodeStringAsFormData(buffer, key, mode); |
192 append(buffer, '='); | 198 append(buffer, '='); |
193 encodeStringAsFormData(buffer, value); | 199 encodeStringAsFormData(buffer, value, mode); |
194 } | 200 } |
195 } | 201 } |
196 | 202 |
197 void FormDataEncoder::encodeStringAsFormData(Vector<char>& buffer, const CString
& string) | 203 void FormDataEncoder::encodeStringAsFormData(Vector<char>& buffer, const CString
& string, Mode mode) |
198 { | 204 { |
199 // Same safe characters as Netscape for compatibility. | 205 // Same safe characters as Netscape for compatibility. |
200 static const char safeCharacters[] = "-._*"; | 206 static const char safeCharacters[] = "-._*"; |
201 | 207 |
202 // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1 | 208 // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1 |
203 unsigned length = string.length(); | 209 unsigned length = string.length(); |
204 for (unsigned i = 0; i < length; ++i) { | 210 for (unsigned i = 0; i < length; ++i) { |
205 unsigned char c = string.data()[i]; | 211 unsigned char c = string.data()[i]; |
206 | 212 |
207 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <
= '9') || strchr(safeCharacters, c)) { | 213 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <
= '9') || (c != '\0' && strchr(safeCharacters, c))) { |
208 append(buffer, c); | 214 append(buffer, c); |
209 } else if (c == ' ') { | 215 } else if (c == ' ') { |
210 append(buffer, '+'); | 216 append(buffer, '+'); |
211 } else if (c == '\n' || (c == '\r' && (i + 1 >= length || string.data()[
i + 1] != '\n'))) { | 217 } else { |
212 append(buffer, "%0D%0A"); | 218 if (mode == NormalizeCRLF) { |
213 } else if (c != '\r') { | 219 if (c == '\n' || (c == '\r' && (i + 1 >= length || string.data()
[i + 1] != '\n'))) { |
214 append(buffer, '%'); | 220 append(buffer, "%0D%0A"); |
215 appendByteAsHex(c, buffer); | 221 } else if (c != '\r') { |
| 222 appendPercentEncoded(buffer, c); |
| 223 } |
| 224 } else { |
| 225 appendPercentEncoded(buffer, c); |
| 226 } |
216 } | 227 } |
217 } | 228 } |
218 } | 229 } |
219 | 230 |
220 } // namespace blink | 231 } // namespace blink |
OLD | NEW |