| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 HH_SET_COOKIE, | 105 HH_SET_COOKIE, |
| 106 HH_TE, | 106 HH_TE, |
| 107 HH_TRAILERS, | 107 HH_TRAILERS, |
| 108 HH_TRANSFER_ENCODING, | 108 HH_TRANSFER_ENCODING, |
| 109 HH_UPGRADE, | 109 HH_UPGRADE, |
| 110 HH_USER_AGENT, | 110 HH_USER_AGENT, |
| 111 HH_WWW_AUTHENTICATE, | 111 HH_WWW_AUTHENTICATE, |
| 112 HH_LAST = HH_WWW_AUTHENTICATE | 112 HH_LAST = HH_WWW_AUTHENTICATE |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 const uint16 HTTP_DEFAULT_PORT = 80; | 115 const uint16_t HTTP_DEFAULT_PORT = 80; |
| 116 const uint16 HTTP_SECURE_PORT = 443; | 116 const uint16_t HTTP_SECURE_PORT = 443; |
| 117 | 117 |
| 118 ////////////////////////////////////////////////////////////////////// | 118 ////////////////////////////////////////////////////////////////////// |
| 119 // Utility Functions | 119 // Utility Functions |
| 120 ////////////////////////////////////////////////////////////////////// | 120 ////////////////////////////////////////////////////////////////////// |
| 121 | 121 |
| 122 inline HttpError mkerr(HttpError err, HttpError def_err = HE_DEFAULT) { | 122 inline HttpError mkerr(HttpError err, HttpError def_err = HE_DEFAULT) { |
| 123 return (err != HE_NONE) ? err : def_err; | 123 return (err != HE_NONE) ? err : def_err; |
| 124 } | 124 } |
| 125 | 125 |
| 126 const char* ToString(HttpVersion version); | 126 const char* ToString(HttpVersion version); |
| 127 bool FromString(HttpVersion& version, const std::string& str); | 127 bool FromString(HttpVersion& version, const std::string& str); |
| 128 | 128 |
| 129 const char* ToString(HttpVerb verb); | 129 const char* ToString(HttpVerb verb); |
| 130 bool FromString(HttpVerb& verb, const std::string& str); | 130 bool FromString(HttpVerb& verb, const std::string& str); |
| 131 | 131 |
| 132 const char* ToString(HttpHeader header); | 132 const char* ToString(HttpHeader header); |
| 133 bool FromString(HttpHeader& header, const std::string& str); | 133 bool FromString(HttpHeader& header, const std::string& str); |
| 134 | 134 |
| 135 inline bool HttpCodeIsInformational(uint32 code) { return ((code / 100) == 1); } | 135 inline bool HttpCodeIsInformational(uint32_t code) { |
| 136 inline bool HttpCodeIsSuccessful(uint32 code) { return ((code / 100) == 2); } | 136 return ((code / 100) == 1); |
| 137 inline bool HttpCodeIsRedirection(uint32 code) { return ((code / 100) == 3); } | 137 } |
| 138 inline bool HttpCodeIsClientError(uint32 code) { return ((code / 100) == 4); } | 138 inline bool HttpCodeIsSuccessful(uint32_t code) { |
| 139 inline bool HttpCodeIsServerError(uint32 code) { return ((code / 100) == 5); } | 139 return ((code / 100) == 2); |
| 140 } |
| 141 inline bool HttpCodeIsRedirection(uint32_t code) { |
| 142 return ((code / 100) == 3); |
| 143 } |
| 144 inline bool HttpCodeIsClientError(uint32_t code) { |
| 145 return ((code / 100) == 4); |
| 146 } |
| 147 inline bool HttpCodeIsServerError(uint32_t code) { |
| 148 return ((code / 100) == 5); |
| 149 } |
| 140 | 150 |
| 141 bool HttpCodeHasBody(uint32 code); | 151 bool HttpCodeHasBody(uint32_t code); |
| 142 bool HttpCodeIsCacheable(uint32 code); | 152 bool HttpCodeIsCacheable(uint32_t code); |
| 143 bool HttpHeaderIsEndToEnd(HttpHeader header); | 153 bool HttpHeaderIsEndToEnd(HttpHeader header); |
| 144 bool HttpHeaderIsCollapsible(HttpHeader header); | 154 bool HttpHeaderIsCollapsible(HttpHeader header); |
| 145 | 155 |
| 146 struct HttpData; | 156 struct HttpData; |
| 147 bool HttpShouldKeepAlive(const HttpData& data); | 157 bool HttpShouldKeepAlive(const HttpData& data); |
| 148 | 158 |
| 149 typedef std::pair<std::string, std::string> HttpAttribute; | 159 typedef std::pair<std::string, std::string> HttpAttribute; |
| 150 typedef std::vector<HttpAttribute> HttpAttributeList; | 160 typedef std::vector<HttpAttribute> HttpAttributeList; |
| 151 void HttpComposeAttributes(const HttpAttributeList& attributes, char separator, | 161 void HttpComposeAttributes(const HttpAttributeList& attributes, char separator, |
| 152 std::string* composed); | 162 std::string* composed); |
| 153 void HttpParseAttributes(const char * data, size_t len, | 163 void HttpParseAttributes(const char * data, size_t len, |
| 154 HttpAttributeList& attributes); | 164 HttpAttributeList& attributes); |
| 155 bool HttpHasAttribute(const HttpAttributeList& attributes, | 165 bool HttpHasAttribute(const HttpAttributeList& attributes, |
| 156 const std::string& name, | 166 const std::string& name, |
| 157 std::string* value); | 167 std::string* value); |
| 158 bool HttpHasNthAttribute(HttpAttributeList& attributes, | 168 bool HttpHasNthAttribute(HttpAttributeList& attributes, |
| 159 size_t index, | 169 size_t index, |
| 160 std::string* name, | 170 std::string* name, |
| 161 std::string* value); | 171 std::string* value); |
| 162 | 172 |
| 163 // Convert RFC1123 date (DoW, DD Mon YYYY HH:MM:SS TZ) to unix timestamp | 173 // Convert RFC1123 date (DoW, DD Mon YYYY HH:MM:SS TZ) to unix timestamp |
| 164 bool HttpDateToSeconds(const std::string& date, time_t* seconds); | 174 bool HttpDateToSeconds(const std::string& date, time_t* seconds); |
| 165 | 175 |
| 166 inline uint16 HttpDefaultPort(bool secure) { | 176 inline uint16_t HttpDefaultPort(bool secure) { |
| 167 return secure ? HTTP_SECURE_PORT : HTTP_DEFAULT_PORT; | 177 return secure ? HTTP_SECURE_PORT : HTTP_DEFAULT_PORT; |
| 168 } | 178 } |
| 169 | 179 |
| 170 // Returns the http server notation for a given address | 180 // Returns the http server notation for a given address |
| 171 std::string HttpAddress(const SocketAddress& address, bool secure); | 181 std::string HttpAddress(const SocketAddress& address, bool secure); |
| 172 | 182 |
| 173 // functional for insensitive std::string compare | 183 // functional for insensitive std::string compare |
| 174 struct iless { | 184 struct iless { |
| 175 bool operator()(const std::string& lhs, const std::string& rhs) const { | 185 bool operator()(const std::string& lhs, const std::string& rhs) const { |
| 176 return (::_stricmp(lhs.c_str(), rhs.c_str()) < 0); | 186 return (::_stricmp(lhs.c_str(), rhs.c_str()) < 0); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 189 public: | 199 public: |
| 190 typedef typename Traits<CTYPE>::string string; | 200 typedef typename Traits<CTYPE>::string string; |
| 191 | 201 |
| 192 // TODO: Implement Encode/Decode | 202 // TODO: Implement Encode/Decode |
| 193 static int Encode(const CTYPE* source, CTYPE* destination, size_t len); | 203 static int Encode(const CTYPE* source, CTYPE* destination, size_t len); |
| 194 static int Encode(const string& source, string& destination); | 204 static int Encode(const string& source, string& destination); |
| 195 static int Decode(const CTYPE* source, CTYPE* destination, size_t len); | 205 static int Decode(const CTYPE* source, CTYPE* destination, size_t len); |
| 196 static int Decode(const string& source, string& destination); | 206 static int Decode(const string& source, string& destination); |
| 197 | 207 |
| 198 Url(const string& url) { do_set_url(url.c_str(), url.size()); } | 208 Url(const string& url) { do_set_url(url.c_str(), url.size()); } |
| 199 Url(const string& path, const string& host, uint16 port = HTTP_DEFAULT_PORT) | 209 Url(const string& path, const string& host, uint16_t port = HTTP_DEFAULT_PORT) |
| 200 : host_(host), port_(port), secure_(HTTP_SECURE_PORT == port) | 210 : host_(host), port_(port), secure_(HTTP_SECURE_PORT == port) { |
| 201 { set_full_path(path); } | 211 set_full_path(path); |
| 212 } |
| 202 | 213 |
| 203 bool valid() const { return !host_.empty(); } | 214 bool valid() const { return !host_.empty(); } |
| 204 void clear() { | 215 void clear() { |
| 205 host_.clear(); | 216 host_.clear(); |
| 206 port_ = HTTP_DEFAULT_PORT; | 217 port_ = HTTP_DEFAULT_PORT; |
| 207 secure_ = false; | 218 secure_ = false; |
| 208 path_.assign(1, static_cast<CTYPE>('/')); | 219 path_.assign(1, static_cast<CTYPE>('/')); |
| 209 query_.clear(); | 220 query_.clear(); |
| 210 } | 221 } |
| 211 | 222 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 226 void set_full_path(const string& val) { | 237 void set_full_path(const string& val) { |
| 227 do_set_full_path(val.c_str(), val.size()); | 238 do_set_full_path(val.c_str(), val.size()); |
| 228 } | 239 } |
| 229 string full_path() const { | 240 string full_path() const { |
| 230 string val; do_get_full_path(&val); return val; | 241 string val; do_get_full_path(&val); return val; |
| 231 } | 242 } |
| 232 | 243 |
| 233 void set_host(const string& val) { host_ = val; } | 244 void set_host(const string& val) { host_ = val; } |
| 234 const string& host() const { return host_; } | 245 const string& host() const { return host_; } |
| 235 | 246 |
| 236 void set_port(uint16 val) { port_ = val; } | 247 void set_port(uint16_t val) { port_ = val; } |
| 237 uint16 port() const { return port_; } | 248 uint16_t port() const { return port_; } |
| 238 | 249 |
| 239 void set_secure(bool val) { secure_ = val; } | 250 void set_secure(bool val) { secure_ = val; } |
| 240 bool secure() const { return secure_; } | 251 bool secure() const { return secure_; } |
| 241 | 252 |
| 242 void set_path(const string& val) { | 253 void set_path(const string& val) { |
| 243 if (val.empty()) { | 254 if (val.empty()) { |
| 244 path_.assign(1, static_cast<CTYPE>('/')); | 255 path_.assign(1, static_cast<CTYPE>('/')); |
| 245 } else { | 256 } else { |
| 246 ASSERT(val[0] == static_cast<CTYPE>('/')); | 257 ASSERT(val[0] == static_cast<CTYPE>('/')); |
| 247 path_ = val; | 258 path_ = val; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 260 private: | 271 private: |
| 261 void do_set_url(const CTYPE* val, size_t len); | 272 void do_set_url(const CTYPE* val, size_t len); |
| 262 void do_set_address(const CTYPE* val, size_t len); | 273 void do_set_address(const CTYPE* val, size_t len); |
| 263 void do_set_full_path(const CTYPE* val, size_t len); | 274 void do_set_full_path(const CTYPE* val, size_t len); |
| 264 | 275 |
| 265 void do_get_url(string* val) const; | 276 void do_get_url(string* val) const; |
| 266 void do_get_address(string* val) const; | 277 void do_get_address(string* val) const; |
| 267 void do_get_full_path(string* val) const; | 278 void do_get_full_path(string* val) const; |
| 268 | 279 |
| 269 string host_, path_, query_; | 280 string host_, path_, query_; |
| 270 uint16 port_; | 281 uint16_t port_; |
| 271 bool secure_; | 282 bool secure_; |
| 272 }; | 283 }; |
| 273 | 284 |
| 274 ////////////////////////////////////////////////////////////////////// | 285 ////////////////////////////////////////////////////////////////////// |
| 275 // HttpData | 286 // HttpData |
| 276 ////////////////////////////////////////////////////////////////////// | 287 ////////////////////////////////////////////////////////////////////// |
| 277 | 288 |
| 278 struct HttpData { | 289 struct HttpData { |
| 279 typedef std::multimap<std::string, std::string, iless> HeaderMap; | 290 typedef std::multimap<std::string, std::string, iless> HeaderMap; |
| 280 typedef HeaderMap::const_iterator const_iterator; | 291 typedef HeaderMap::const_iterator const_iterator; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 void copy(const HttpRequestData& src); | 397 void copy(const HttpRequestData& src); |
| 387 | 398 |
| 388 size_t formatLeader(char* buffer, size_t size) const override; | 399 size_t formatLeader(char* buffer, size_t size) const override; |
| 389 HttpError parseLeader(const char* line, size_t len) override; | 400 HttpError parseLeader(const char* line, size_t len) override; |
| 390 | 401 |
| 391 bool getAbsoluteUri(std::string* uri) const; | 402 bool getAbsoluteUri(std::string* uri) const; |
| 392 bool getRelativeUri(std::string* host, std::string* path) const; | 403 bool getRelativeUri(std::string* host, std::string* path) const; |
| 393 }; | 404 }; |
| 394 | 405 |
| 395 struct HttpResponseData : public HttpData { | 406 struct HttpResponseData : public HttpData { |
| 396 uint32 scode; | 407 uint32_t scode; |
| 397 std::string message; | 408 std::string message; |
| 398 | 409 |
| 399 HttpResponseData() : scode(HC_INTERNAL_SERVER_ERROR) { } | 410 HttpResponseData() : scode(HC_INTERNAL_SERVER_ERROR) { } |
| 400 void clear(bool release_document); | 411 void clear(bool release_document); |
| 401 void copy(const HttpResponseData& src); | 412 void copy(const HttpResponseData& src); |
| 402 | 413 |
| 403 // Convenience methods | 414 // Convenience methods |
| 404 void set_success(uint32 scode = HC_OK); | 415 void set_success(uint32_t scode = HC_OK); |
| 405 void set_success(const std::string& content_type, StreamInterface* document, | 416 void set_success(const std::string& content_type, |
| 406 uint32 scode = HC_OK); | 417 StreamInterface* document, |
| 418 uint32_t scode = HC_OK); |
| 407 void set_redirect(const std::string& location, | 419 void set_redirect(const std::string& location, |
| 408 uint32 scode = HC_MOVED_TEMPORARILY); | 420 uint32_t scode = HC_MOVED_TEMPORARILY); |
| 409 void set_error(uint32 scode); | 421 void set_error(uint32_t scode); |
| 410 | 422 |
| 411 size_t formatLeader(char* buffer, size_t size) const override; | 423 size_t formatLeader(char* buffer, size_t size) const override; |
| 412 HttpError parseLeader(const char* line, size_t len) override; | 424 HttpError parseLeader(const char* line, size_t len) override; |
| 413 }; | 425 }; |
| 414 | 426 |
| 415 struct HttpTransaction { | 427 struct HttpTransaction { |
| 416 HttpRequestData request; | 428 HttpRequestData request; |
| 417 HttpResponseData response; | 429 HttpResponseData response; |
| 418 }; | 430 }; |
| 419 | 431 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 437 const SocketAddress& server, | 449 const SocketAddress& server, |
| 438 const std::string& method, const std::string& uri, | 450 const std::string& method, const std::string& uri, |
| 439 const std::string& username, const CryptString& password, | 451 const std::string& username, const CryptString& password, |
| 440 HttpAuthContext *& context, std::string& response, std::string& auth_method); | 452 HttpAuthContext *& context, std::string& response, std::string& auth_method); |
| 441 | 453 |
| 442 ////////////////////////////////////////////////////////////////////// | 454 ////////////////////////////////////////////////////////////////////// |
| 443 | 455 |
| 444 } // namespace rtc | 456 } // namespace rtc |
| 445 | 457 |
| 446 #endif // WEBRTC_BASE_HTTPCOMMON_H__ | 458 #endif // WEBRTC_BASE_HTTPCOMMON_H__ |
| OLD | NEW |