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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 169 } |
170 return ProcessHeader(line, nlen, value, vlen, error); | 170 return ProcessHeader(line, nlen, value, vlen, error); |
171 } else { | 171 } else { |
172 state_ = chunked_ ? ST_CHUNKSIZE : ST_DATA; | 172 state_ = chunked_ ? ST_CHUNKSIZE : ST_DATA; |
173 return ProcessHeaderComplete(chunked_, data_size_, error); | 173 return ProcessHeaderComplete(chunked_, data_size_, error); |
174 } | 174 } |
175 break; | 175 break; |
176 | 176 |
177 case ST_CHUNKSIZE: | 177 case ST_CHUNKSIZE: |
178 if (len > 0) { | 178 if (len > 0) { |
179 char* ptr = NULL; | 179 char* ptr = nullptr; |
180 data_size_ = strtoul(line, &ptr, 16); | 180 data_size_ = strtoul(line, &ptr, 16); |
181 if (ptr != line + len) { | 181 if (ptr != line + len) { |
182 *error = HE_PROTOCOL; | 182 *error = HE_PROTOCOL; |
183 return PR_COMPLETE; | 183 return PR_COMPLETE; |
184 } | 184 } |
185 state_ = (data_size_ == 0) ? ST_TRAILERS : ST_DATA; | 185 state_ = (data_size_ == 0) ? ST_TRAILERS : ST_DATA; |
186 } else { | 186 } else { |
187 *error = HE_PROTOCOL; | 187 *error = HE_PROTOCOL; |
188 return PR_COMPLETE; | 188 return PR_COMPLETE; |
189 } | 189 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 StreamResult DoReserve(size_t size, int* error) override { | 238 StreamResult DoReserve(size_t size, int* error) override { |
239 return (buffer_length_ >= size) ? SR_SUCCESS : SR_BLOCK; | 239 return (buffer_length_ >= size) ? SR_SUCCESS : SR_BLOCK; |
240 } | 240 } |
241 }; | 241 }; |
242 | 242 |
243 class HttpBase::DocumentStream : public StreamInterface { | 243 class HttpBase::DocumentStream : public StreamInterface { |
244 public: | 244 public: |
245 DocumentStream(HttpBase* base) : base_(base), error_(HE_DEFAULT) { } | 245 DocumentStream(HttpBase* base) : base_(base), error_(HE_DEFAULT) { } |
246 | 246 |
247 StreamState GetState() const override { | 247 StreamState GetState() const override { |
248 if (NULL == base_) | 248 if (nullptr == base_) |
249 return SS_CLOSED; | 249 return SS_CLOSED; |
250 if (HM_RECV == base_->mode_) | 250 if (HM_RECV == base_->mode_) |
251 return SS_OPEN; | 251 return SS_OPEN; |
252 return SS_OPENING; | 252 return SS_OPENING; |
253 } | 253 } |
254 | 254 |
255 StreamResult Read(void* buffer, | 255 StreamResult Read(void* buffer, |
256 size_t buffer_len, | 256 size_t buffer_len, |
257 size_t* read, | 257 size_t* read, |
258 int* error) override { | 258 int* error) override { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 return false; | 335 return false; |
336 size_t data_size = base_->GetDataRemaining(); | 336 size_t data_size = base_->GetDataRemaining(); |
337 if (SIZE_UNKNOWN == data_size) | 337 if (SIZE_UNKNOWN == data_size) |
338 return false; | 338 return false; |
339 if (size) | 339 if (size) |
340 *size = data_size; | 340 *size = data_size; |
341 return true; | 341 return true; |
342 } | 342 } |
343 | 343 |
344 HttpBase* Disconnect(HttpError error) { | 344 HttpBase* Disconnect(HttpError error) { |
345 RTC_DCHECK(NULL != base_); | 345 RTC_DCHECK(nullptr != base_); |
346 RTC_DCHECK(NULL != base_->doc_stream_); | 346 RTC_DCHECK(nullptr != base_->doc_stream_); |
347 HttpBase* base = base_; | 347 HttpBase* base = base_; |
348 base_->doc_stream_ = NULL; | 348 base_->doc_stream_ = nullptr; |
349 base_ = NULL; | 349 base_ = nullptr; |
350 error_ = error; | 350 error_ = error; |
351 return base; | 351 return base; |
352 } | 352 } |
353 | 353 |
354 private: | 354 private: |
355 HttpBase* base_; | 355 HttpBase* base_; |
356 HttpError error_; | 356 HttpError error_; |
357 }; | 357 }; |
358 | 358 |
359 ////////////////////////////////////////////////////////////////////// | 359 ////////////////////////////////////////////////////////////////////// |
360 // HttpBase | 360 // HttpBase |
361 ////////////////////////////////////////////////////////////////////// | 361 ////////////////////////////////////////////////////////////////////// |
362 | 362 |
363 HttpBase::HttpBase() : mode_(HM_NONE), data_(NULL), notify_(NULL), | 363 HttpBase::HttpBase() |
364 http_stream_(NULL), doc_stream_(NULL) { | 364 : mode_(HM_NONE), |
365 } | 365 data_(nullptr), |
| 366 notify_(nullptr), |
| 367 http_stream_(nullptr), |
| 368 doc_stream_(nullptr) {} |
366 | 369 |
367 HttpBase::~HttpBase() { | 370 HttpBase::~HttpBase() { |
368 RTC_DCHECK(HM_NONE == mode_); | 371 RTC_DCHECK(HM_NONE == mode_); |
369 } | 372 } |
370 | 373 |
371 bool | 374 bool |
372 HttpBase::isConnected() const { | 375 HttpBase::isConnected() const { |
373 return (http_stream_ != NULL) && (http_stream_->GetState() == SS_OPEN); | 376 return (http_stream_ != nullptr) && (http_stream_->GetState() == SS_OPEN); |
374 } | 377 } |
375 | 378 |
376 bool | 379 bool |
377 HttpBase::attach(StreamInterface* stream) { | 380 HttpBase::attach(StreamInterface* stream) { |
378 if ((mode_ != HM_NONE) || (http_stream_ != NULL) || (stream == NULL)) { | 381 if ((mode_ != HM_NONE) || (http_stream_ != nullptr) || (stream == nullptr)) { |
379 RTC_NOTREACHED(); | 382 RTC_NOTREACHED(); |
380 return false; | 383 return false; |
381 } | 384 } |
382 http_stream_ = stream; | 385 http_stream_ = stream; |
383 http_stream_->SignalEvent.connect(this, &HttpBase::OnHttpStreamEvent); | 386 http_stream_->SignalEvent.connect(this, &HttpBase::OnHttpStreamEvent); |
384 mode_ = (http_stream_->GetState() == SS_OPENING) ? HM_CONNECT : HM_NONE; | 387 mode_ = (http_stream_->GetState() == SS_OPENING) ? HM_CONNECT : HM_NONE; |
385 return true; | 388 return true; |
386 } | 389 } |
387 | 390 |
388 StreamInterface* | 391 StreamInterface* |
389 HttpBase::detach() { | 392 HttpBase::detach() { |
390 RTC_DCHECK(HM_NONE == mode_); | 393 RTC_DCHECK(HM_NONE == mode_); |
391 if (mode_ != HM_NONE) { | 394 if (mode_ != HM_NONE) { |
392 return NULL; | 395 return nullptr; |
393 } | 396 } |
394 StreamInterface* stream = http_stream_; | 397 StreamInterface* stream = http_stream_; |
395 http_stream_ = NULL; | 398 http_stream_ = nullptr; |
396 if (stream) { | 399 if (stream) { |
397 stream->SignalEvent.disconnect(this); | 400 stream->SignalEvent.disconnect(this); |
398 } | 401 } |
399 return stream; | 402 return stream; |
400 } | 403 } |
401 | 404 |
402 void | 405 void |
403 HttpBase::send(HttpData* data) { | 406 HttpBase::send(HttpData* data) { |
404 RTC_DCHECK(HM_NONE == mode_); | 407 RTC_DCHECK(HM_NONE == mode_); |
405 if (mode_ != HM_NONE) { | 408 if (mode_ != HM_NONE) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 if (doc_stream_) { | 458 if (doc_stream_) { |
456 doc_stream_->SignalEvent(doc_stream_, SE_OPEN | SE_READ, 0); | 459 doc_stream_->SignalEvent(doc_stream_, SE_OPEN | SE_READ, 0); |
457 } else { | 460 } else { |
458 read_and_process_data(); | 461 read_and_process_data(); |
459 } | 462 } |
460 } | 463 } |
461 | 464 |
462 void | 465 void |
463 HttpBase::abort(HttpError err) { | 466 HttpBase::abort(HttpError err) { |
464 if (mode_ != HM_NONE) { | 467 if (mode_ != HM_NONE) { |
465 if (http_stream_ != NULL) { | 468 if (http_stream_ != nullptr) { |
466 http_stream_->Close(); | 469 http_stream_->Close(); |
467 } | 470 } |
468 do_complete(err); | 471 do_complete(err); |
469 } | 472 } |
470 } | 473 } |
471 | 474 |
472 StreamInterface* HttpBase::GetDocumentStream() { | 475 StreamInterface* HttpBase::GetDocumentStream() { |
473 if (doc_stream_) | 476 if (doc_stream_) |
474 return NULL; | 477 return nullptr; |
475 doc_stream_ = new DocumentStream(this); | 478 doc_stream_ = new DocumentStream(this); |
476 return doc_stream_; | 479 return doc_stream_; |
477 } | 480 } |
478 | 481 |
479 HttpError HttpBase::HandleStreamClose(int error) { | 482 HttpError HttpBase::HandleStreamClose(int error) { |
480 if (http_stream_ != NULL) { | 483 if (http_stream_ != nullptr) { |
481 http_stream_->Close(); | 484 http_stream_->Close(); |
482 } | 485 } |
483 if (error == 0) { | 486 if (error == 0) { |
484 if ((mode_ == HM_RECV) && is_valid_end_of_input()) { | 487 if ((mode_ == HM_RECV) && is_valid_end_of_input()) { |
485 return HE_NONE; | 488 return HE_NONE; |
486 } else { | 489 } else { |
487 return HE_DISCONNECTED; | 490 return HE_DISCONNECTED; |
488 } | 491 } |
489 } else if (error == SOCKET_EACCES) { | 492 } else if (error == SOCKET_EACCES) { |
490 return HE_AUTH; | 493 return HE_AUTH; |
491 } else if (error == SEC_E_CERT_EXPIRED) { | 494 } else if (error == SEC_E_CERT_EXPIRED) { |
492 return HE_CERTIFICATE_EXPIRED; | 495 return HE_CERTIFICATE_EXPIRED; |
493 } | 496 } |
494 LOG_F(LS_ERROR) << "(" << error << ")"; | 497 LOG_F(LS_ERROR) << "(" << error << ")"; |
495 return (HM_CONNECT == mode_) ? HE_CONNECT_FAILED : HE_SOCKET_ERROR; | 498 return (HM_CONNECT == mode_) ? HE_CONNECT_FAILED : HE_SOCKET_ERROR; |
496 } | 499 } |
497 | 500 |
498 bool HttpBase::DoReceiveLoop(HttpError* error) { | 501 bool HttpBase::DoReceiveLoop(HttpError* error) { |
499 RTC_DCHECK(HM_RECV == mode_); | 502 RTC_DCHECK(HM_RECV == mode_); |
500 RTC_DCHECK(NULL != error); | 503 RTC_DCHECK(nullptr != error); |
501 | 504 |
502 // Do to the latency between receiving read notifications from | 505 // Do to the latency between receiving read notifications from |
503 // pseudotcpchannel, we rely on repeated calls to read in order to acheive | 506 // pseudotcpchannel, we rely on repeated calls to read in order to acheive |
504 // ideal throughput. The number of reads is limited to prevent starving | 507 // ideal throughput. The number of reads is limited to prevent starving |
505 // the caller. | 508 // the caller. |
506 | 509 |
507 size_t loop_count = 0; | 510 size_t loop_count = 0; |
508 const size_t kMaxReadCount = 20; | 511 const size_t kMaxReadCount = 20; |
509 bool process_requires_more_data = false; | 512 bool process_requires_more_data = false; |
510 do { | 513 do { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 } | 733 } |
731 | 734 |
732 void | 735 void |
733 HttpBase::do_complete(HttpError err) { | 736 HttpBase::do_complete(HttpError err) { |
734 RTC_DCHECK(mode_ != HM_NONE); | 737 RTC_DCHECK(mode_ != HM_NONE); |
735 HttpMode mode = mode_; | 738 HttpMode mode = mode_; |
736 mode_ = HM_NONE; | 739 mode_ = HM_NONE; |
737 if (data_ && data_->document) { | 740 if (data_ && data_->document) { |
738 data_->document->SignalEvent.disconnect(this); | 741 data_->document->SignalEvent.disconnect(this); |
739 } | 742 } |
740 data_ = NULL; | 743 data_ = nullptr; |
741 if ((HM_RECV == mode) && doc_stream_) { | 744 if ((HM_RECV == mode) && doc_stream_) { |
742 RTC_DCHECK(HE_NONE != | 745 RTC_DCHECK(HE_NONE != |
743 err); // We should have Disconnected doc_stream_ already. | 746 err); // We should have Disconnected doc_stream_ already. |
744 DocumentStream* ds = doc_stream_; | 747 DocumentStream* ds = doc_stream_; |
745 ds->Disconnect(err); | 748 ds->Disconnect(err); |
746 ds->SignalEvent(ds, SE_CLOSE, err); | 749 ds->SignalEvent(ds, SE_CLOSE, err); |
747 } | 750 } |
748 if (notify_) { | 751 if (notify_) { |
749 notify_->onHttpComplete(mode, err); | 752 notify_->onHttpComplete(mode, err); |
750 } | 753 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 return PR_CONTINUE; | 830 return PR_CONTINUE; |
828 } | 831 } |
829 | 832 |
830 HttpParser::ProcessResult | 833 HttpParser::ProcessResult |
831 HttpBase::ProcessHeaderComplete(bool chunked, size_t& data_size, | 834 HttpBase::ProcessHeaderComplete(bool chunked, size_t& data_size, |
832 HttpError* error) { | 835 HttpError* error) { |
833 StreamInterface* old_docstream = doc_stream_; | 836 StreamInterface* old_docstream = doc_stream_; |
834 if (notify_) { | 837 if (notify_) { |
835 *error = notify_->onHttpHeaderComplete(chunked, data_size); | 838 *error = notify_->onHttpHeaderComplete(chunked, data_size); |
836 // The request must not be aborted as a result of this callback. | 839 // The request must not be aborted as a result of this callback. |
837 RTC_DCHECK(NULL != data_); | 840 RTC_DCHECK(nullptr != data_); |
838 } | 841 } |
839 if ((HE_NONE == *error) && data_->document) { | 842 if ((HE_NONE == *error) && data_->document) { |
840 data_->document->SignalEvent.connect(this, &HttpBase::OnDocumentEvent); | 843 data_->document->SignalEvent.connect(this, &HttpBase::OnDocumentEvent); |
841 } | 844 } |
842 if (HE_NONE != *error) { | 845 if (HE_NONE != *error) { |
843 return PR_COMPLETE; | 846 return PR_COMPLETE; |
844 } | 847 } |
845 if (old_docstream != doc_stream_) { | 848 if (old_docstream != doc_stream_) { |
846 // Break out of Process loop, since our I/O model just changed. | 849 // Break out of Process loop, since our I/O model just changed. |
847 return PR_BLOCK; | 850 return PR_BLOCK; |
(...skipping 26 matching lines...) Expand all Loading... |
874 } | 877 } |
875 } | 878 } |
876 | 879 |
877 void | 880 void |
878 HttpBase::OnComplete(HttpError err) { | 881 HttpBase::OnComplete(HttpError err) { |
879 LOG_F(LS_VERBOSE); | 882 LOG_F(LS_VERBOSE); |
880 do_complete(err); | 883 do_complete(err); |
881 } | 884 } |
882 | 885 |
883 } // namespace rtc | 886 } // namespace rtc |
OLD | NEW |